ROCKSDB는 임베드 가능 하고 지속적인 키 가치 저장소입니다.
다음 소개는 RocksDB 중국 공식 웹 사이트에서 나옵니다
https://rocksdb.org.cn/
다음 4 가지 특성이 있습니다
1 고성능 : ROCKSDB는 일련의 로그 구조 데이터베이스 엔진을 사용합니다. 더 나은 성능을 위해이 엔진은 C ++로 작성됩니다. 키와 값은 모든 크기의 바이트 스트림입니다.
2 빠른 스토리지를 위해 최적화 : RocksDB는 빠르고 저도 저장 장치 (예 : 플래시 메모리 또는 고속 하드 디스크)에 특별히 최적화되어 있습니다. ROCKSDB는 플래시 메모리 및 RAM의 고위급 읽기 및 쓰기 성능을 최대화합니다.
3ADAPILIDAY : ROCKSDB는 다양한 유형의 워크로드에 적합합니다. MyRocks와 같은 데이터 스토리지 엔진에서 응용 프로그램 데이터 캐싱 및 일부 임베디드 워크로드까지 RocksDB는 이러한 다양한 데이터 워크로드 요구를 침착하게 직면 할 수 있습니다.
4 기본 및 고급 데이터베이스 작업 RocksDB는 데이터베이스를 열고 닫는 것과 같은 기본 작업을 제공합니다. 병합 및 압축 필터링과 같은 고급 작업에 대한 읽기 및 쓰기 지원도 제공됩니다.
ROCKDB 설치 및 사용
RocksDB를 설치하는 방법에는 여러 가지가 있습니다. 공무원은 해당 플랫폼에 이진 라이브러리를 제공하지 않으므로 자체적으로 편집하고 사용해야합니다.
ROCKSDB 설치는 매우 간단하지만 RocksDB에 대한보기를 변경해야합니다. 헤비급 데이터베이스가 아니며 내장 된 키 가치 저장소입니다. 즉, Maven 프로젝트에 RocksDB 의존성을 추가하여 개발 환경에서 직접 시도 할 수 있습니다. 이것을 이해하지 못하면 다음 두 가지 권장되지 않은 설치 방법으로 이동할 수 있습니다.
RocksDB의 공식 웹 사이트를 확인하면 C ++ 프로그램을 작성해야한다는 것을 알게됩니다 (권장되지 않음).
#include <Assert> #include "rocksdb/db.h"rocksdb :: db* db; rocksdb :: 옵션 옵션; 옵션 .create_if_missing = true; rocksdb :: 상태 상태 = rocksdb :: db :: open (옵션, "/tmp/testdb", & db);
데이터베이스를 만드시겠습니까? ? ? ? 이전에 사용한 MySQL이나 몽고와 다른 이유는 무엇입니까? START.SH 또는 START.BAT와 같은 스크립트가없는 이유는 무엇입니까? 내가 글을 쓰길 바라나요? 글을 쓰고 나서 나는 그것을 RocksDB 라이브러리와 연관시키는 방법을 몰랐다는 것을 알았습니다. 무엇을해야합니까? C ++에 대해 잊었습니다.
방법 2는 pyrocksdb를 사용합니다 (권장되지 않음)
http://pyrocksdb.readthedocs.io/en/latest/installation.html
자세한 설치 문서는 PyrocksDB의 공식 웹 사이트 설치 문서를 참조하십시오.
위의 두 가지 방법은 C ++ 또는 Python에 익숙하지만 Java 개발자에게는 그다지 친숙하지 않은 개발자에게 더 친숙합니다.
다음으로 세 번째 방법을 소개하겠습니다.
방법 3 Maven 사용 (권장)
새 Maven 프로젝트를 만들고 pom.xml 종속성을 수정하여 추가하십시오.
<pectionency> <groupid> org.rocksdb </groupid> <artifactid> rocksdbjni </artifactid> <버전> 5.8.6 </version> </fectionency>
좋아하는 버전을 선택할 수 있습니다.
그런 다음 Maven의 언어 수준이 높아서 전 세계적으로 1.8로 설정했습니다.
<profiles> <profile> <id> jdk18 </id> <활성화> <ctiveByDefault> true </activeByDefault> <JDK> 1.8 </jdk> </activation> <properties> <maven.compiler.source> 1.8 </maven.compiler.source> <maven.compiler.target> 1.8 </maven.compiler.target> <maven.compiler.compilerversion> 1.8 </maven.compiler.compilerversion> </properties> </profile> </profiles>
이 시점에서 환경이 준비되었습니다. 친숙한 자바 세계로 돌아 왔습니까?
그런 다음 IDE에서 실행중인 구성을 수정하고 데이터베이스 저장 경로에 프로그램을 추가 한 다음 테스트를 실행하십시오. 나는 기사 끝에이 수업을 줄 것이다.
콘솔을 실행할 때 로그 출력이 있으며 파일에 새 파일도 나타납니다.
ROCKDB 개발 API 및 나중에 생산 응용 프로그램에 대한 자세한 내용을 업데이트 할 것입니다. 모두가주의를 기울이기를 바랍니다.
// Copyright (C) 2011-Present, Facebook, Inc. 모든 권리 보유 .//이 소스 코드는 GPLV2 (루트 디렉토리의 // 복사 파일에 찾을 수 있음)와 APACHE 2.0 라이센스 // (루트 디렉토리에 LICENCE.APACHE 파일에 찾을 수 있음). java.util.arraylist; import java.util.arrays; import java.util.list; import java.util.map; public class rocksdbsample {static {rocksdb.loadlibrary (); } public static void main (최종 문자열 [] args) {if (args.length <1) {System.out.println ( "usage : rocksdbsample db_path"); System.exit (-1); } 최종 문자열 db_path = args [0]; 최종 문자열 db_path_not_found = db_path + "_not_found"; System.out.println ( "rocksdbsample"); try (최종 옵션 옵션 = 새로운 옵션 (); 최종 필터 BloomFilter = New BloomFilter = 새로운 BloomFilter = 최종 readoptions readoptions = new readoptions () .SetFillCache (false); 최종 통계 통계 = 새로운 통계 (); 최종 Ratelimiter = New Ratelimiter (100000000,10000, 10) {옵션, rocksdb = rocksdb. db_path_not_found)) {assert (false); } catch (Final RocksDBexception e) {System.out.Format ( "예상 예외 - %s/n", e); } try {options.setCreateIfMissing (true) .setStatistics (stats) .setWriteBuffersize (8 * sizeUnit.kb) .setMaxWriteBufferNumber (3) .setMaxBackBackPections (10) .setCompressionType (compressionType.snappy_compression). } catch (Final OregalArgumentException e) {assert (false); } assert (옵션 .createifmissing () == true); assert (옵션 .writeBuffersize () == 8 * sizeUnit.kb); assert (옵션 .maxWriteBufferNumber () == 3); assert (옵션 .maxbackbackgroundcompactions () == 10); assert (옵션.compressiontype () == compressionType.snappy_compression); assert (옵션.comPactionStyle () == CompactionStyle.Universal); assert (옵션 .memtableFactoryName (). Equals ( "SkipListFactory"); 옵션 .setMemtableConfig (New HashskiplistMemtableConfig () .setheight (4) .SetBranchingFactor (4) .SetBucketCount (2000000)); assert (옵션 .memtableFactoryName (). 옵션 .setMemtableConfig (New HashlinkedListMemtableConfig () .setBucketCount (100000)); assert (옵션 .memtableFactoryName (). 옵션 .setmemtableConfig (new vectormemtableConfig (). setReservedSize (10000)); assert (옵션 .memtableFactoryName (). Equals ( "VectorRepFactory")); 옵션 .setmemtableConfig (New SkipListMemtableConfig ()); assert (옵션 .memtableFactoryName (). Equals ( "SkipListFactory"); 옵션 .settableformatconfig (new PlaintableConfig ()); // Plain-Table이 필요합니다 MMAP 읽기 옵션 .SetallowMPREADS (true); assert (옵션 .TableFactoryName (). Equals ( "Plaintable")); 옵션 .SetRatelimiter (Ratelimiter); Final BlockbasedTableConfig Table_Options = New BlockbasedTableConfig (); table_options.setBlockCachesize (64 * sizeUnit.kb) .SetFilter (bloomFilter) .SetCachenumShardBits (6) .SetBlockSizeIce (5) .SetBlockRestArtInterVal (10) .setCacheIndexAndFilterBlocks (true) .SetShashIndexalCollission (SETETHSHECCOCCHOLLSISION). sizeUnit.kb) .setBlockCacheCompressedNumshardBits (10); assert (table_options.blockCachesize () == 64 * sizeUnit.kb); assert (table_options.cachenumshardBits () == 6); assert (table_options.blocksizedeviation () == 5); assert (table_options.blockrestartInterval () == 10); assert (table_options.cacheIndexAndFilterBlocks () == true); assert (table_options.hashindexallowcollision () == false); assert (table_options.blockCachecompressedSize () == 64 * sizeUnit.kb); assert (table_options.blockCachecompressedNumshardBits () == 10); 옵션 .settableformatconfig (table_options); assert (옵션 .tableFactoryName (). try (final rocksdb db = rocksdb.open (옵션, db_path)) {db.put ( "hello".getbytes (), "world".getBytes ()); 최종 바이트 [] value = db.get ( "hello".getBytes ()); assert ( "world".equals (새 문자열 (value)); 최종 문자열 str = db.getProperty ( "rocksdb.stats"); assert (str! = null &&! str.equals ( "")); } catch (Final RocksDBexception e) {System.out.Format ( "[ERROR] 예상치 못한 예외를 잡았습니다 - %s/n", e); assert (false); } try (final rocksdb db = rocksdb.open (옵션, db_path)) {db.put ( "hello".getBytes (), "world".getBytes ()); 바이트 [] value = db.get ( "hello".getBytes ()); system.out.format ( "get ( 'hello') = %s/n", 새 문자열 (value)); for (int i = 1; i <= 9; ++ i) {for (int j = 1; j <= 9; ++ j) {db.put (string.format ( "%dx%d", i, j) .getBytes (), String.format ( "%d", i * j) .getBytes ()); }} for (int i = 1; i <= 9; ++ i) {for (int j = 1; j <= 9; ++ j) {system.out.format ( "%s", new String (db.get (String.format ( "%dx%d", i, j))); } system.out.println ( ""); } // write batch test try (final writeOptions writeOpt = new writeOptions ()) {for (int i = 10; i <= 19; ++ i) {try (final writebatch batch = new writeBatch ()) {for (int j = 10; string.format ( "%d", i * j) .getBytes ()); } db.write (writeOpt, batch); }}} for (int i = 10; i <= 19; ++ i) {for (int j = 10; j <= 19; ++ j) {assert (new String (db.get (String.format ( "%dx%d", i, j)) .getBytes (string.format ( "%d", i * j)); system.out.format ( "%s", 새 문자열 (db.get (String.format ( "%dx%d", i, j) .getBytes ())); } system.out.println ( ""); } value = db.get ( "1x1".getBytes ()); assert (value! = null); value = db.get ( "world".getBytes ()); assert (value == null); value = db.get (readoptions, "world".getBytes ()); assert (value == null); 최종 바이트 [] testkey = "asdf".getBytes (); 최종 바이트 [] testValue = "asdfghjkl; '?> <mnbvcxzqwertyuiop {+_) (*&^%$#@". getBytes (); db.put (testkey, testValue); byte [] testresult = db.get (testke); Assert! = null); (TestValue, TestResult) (TestValue (testValue) (TestResult) (readoptions, testkey); String (testresult); = rocksdb.not_found. Assert (rocksdb.not_found) writeOpts () {writeOpts.setSync (true); LEN));} for (최종 TickerType Statstype : TickerType.Values ()) {if (statStype! = TickerType.ticker_enum_max) {stats.getTickerCount (statStype)} (gettickercount); system.out.println (gettickercount ()에 대한 호출 실패 "; gethistogramdata (histogramtype)}} println (gethistogramdata)} {system.out.println (gethistortater); db.newiterator () {iterator.isvalid (); iterator.status () if (seektofirstpassed) {System.out.println (ITERATOR.Seektolast (); iterator.isvalid () (value ()! (iterator.value ()! = null). iterator.isvalid (); null) 값 = db.multiget (), keys (values.size.size ();위는 이번에는 RocksDB 설치 및 Java의 응용 프로그램의 전체 내용입니다. 학습 후에도 아무것도 이해하지 못하면 아래 메시지 영역에서 논의 할 수 있습니다. wulin.com을 지원 해주셔서 감사합니다.