The problem that the pit data that java levedb uses all the way cannot be completely deleted, etc.

For more information about leveldb can refer to the text of the article for levedb

1 java version of leveldb library

 I first used this library when I heard someone introduce it, and I have been using this library. Later, I found that the library deleted data, it could not be deleted from the hard disk. Checking the information also said that the
data will be deleted under certain circumstances, but during the use process , There is no release of hard disk resources.

  <dependency>
            <groupId>org.iq80.leveldb</groupId>
            <artifactId>leveldb</artifactId>
            <version>0.12</version>
        </dependency>

  Previously it was just used to store some configuration, and the amount of data was not too big, so I didn't care too much; now I want to do some data caching, compared with sqlite, etc., levedb is better. The data deletion problem must be solved. So looking at the introduction of levedb source code, I found that the interface to delete and release resources has been implemented, but the java version of org.iq80.leveldb has not been implemented.

2 leveldb jni

I rushed and rushed online and found org.fusesource.leveldbjni; called the c dynamic library; provided the db.compactRange(null, null) method; could solve the problem of data deletion and release hard disk resources; in addition, the cached data was compressed by 20 times, but The compression effect of java version library is less than 2 times.
  This package provides dynamic libraries of linux32, linux64, osx, window32, and window64 versions.

      <dependency>
          <groupId>org.fusesource.leveldbjni</groupId>
          <artifactId>leveldbjni-all</artifactId>
          <version>1.8</version>
      </dependency>


  

3 Other system problem handling

 Since the program is running on the Raspberry Pi arvm7, it is not provided in leveldbjni-all, you need to download the source code to compile and put it in the system folder;

Download source code

If the snappy download fails, you can download it here

wget http://snappy.googlecode.com/files/snappy-1.0.5.tar.gz
tar -zxvf snappy-1.0.5.tar.gz
git clone git://github.com/chirino/leveldb.git
git clone git://github.com/fusesource/leveldbjni.git
export SNAPPY_HOME=`cd snappy-1.0.5; pwd`
export LEVELDB_HOME=`cd leveldb; pwd`
export LEVELDBJNI_HOME=`cd leveldbjni; pwd`

Compile snappy

cd ${SNAPPY_HOME}
./configure --disable-shared --with-pic
make

 

Compile leveldb

cd ${LEVELDB_HOME}
export LIBRARY_PATH=${SNAPPY_HOME}
export C_INCLUDE_PATH=${LIBRARY_PATH}
export CPLUS_INCLUDE_PATH=${LIBRARY_PATH}
git apply ../leveldbjni/leveldb.patch
make libleveldb.a

mvn leveldbjni

cd ${LEVELDBJNI_HOME}
mvn clean install -P download -P armv7


After the packaging is complete, unzip the leveldbjni-arvm7-99-master-SNAPSHOT to obtain the liblevedbjni.so library and put it under /usr/lib.

 

Guess you like

Origin blog.csdn.net/h4241778/article/details/108608203