def testMeasureWriteTime(tempdir): store = TextFileStore(tempdir, 'benchWithSync', isLineNoKey=True, storeContentHash=False) hashes = [hexlify(h).decode() for h in generateHashes(1000)] start = time.time() for h in hashes: store.put(key=None, value=h) timeTakenWithSync = time.time() - start store = TextFileStore(tempdir, 'benchWithoutSync', isLineNoKey=True, storeContentHash=False, ensureDurability=False) start = time.time() for h in hashes: store.put(key=None, value=h) timeTakenWithoutSync = time.time() - start print("Time taken to write {} entries to file with fsync is {} " "seconds".format(len(hashes), timeTakenWithSync)) print("Time taken to write {} entries to file without fsync is {} " "seconds".format(len(hashes), timeTakenWithoutSync)) print("So the difference is {} seconds".format(timeTakenWithSync - timeTakenWithoutSync)) # On most platforms the ratio between write time with fsync and # write time without fsync typically must be greater than 100. # But on Windows Server 2012 this ratio may be less - down to 30. assert timeTakenWithoutSync * 10 < timeTakenWithSync, "ratio is {}".\ format(timeTakenWithSync / timeTakenWithoutSync)
def test_leveldb_and_text_store_equality(tmpdir): """ This test verifies that TextFileStore and LeveldbStore behave equally """ isLineNoKey = True storeContentHash = False ensureDurability = True dbDir = str(tmpdir) text_store = TextFileStore(dbDir=dbDir, dbName="text_data", isLineNoKey=isLineNoKey, storeContentHash=storeContentHash, ensureDurability=ensureDurability) leveldb_store = KeyValueStorageLeveldb(dbDir, "leveldb_data") for i in range(1, 10): value = "Some data {}".format(str(i)) text_store.put(None, value) leveldb_store.put(str(i), value) assert text_store.get(str(i)) assert leveldb_store.get(str(i)).decode() == text_store.get(str(i)) assert list(v.decode() for k, v in leveldb_store.iterator()) == \ list(v for k, v in text_store.iterator())
def create_initiator_ledger(self) -> Ledger: store = TextFileStore(self.__data_dir, self.__db_name, isLineNoKey=True, storeContentHash=False, ensureDurability=False) return Ledger(CompactMerkleTree(), dataDir=self.__data_dir, txn_serializer=self.__serializer, fileName=self.__db_name, transactionLogStore=store)
def test_chunked_and_text_store_equality(tmpdir): """ This test verifies that TextFileStore and ChunkedFileStore behave equally """ isLineNoKey = True storeContentHash = False ensureDurability = True dbDir = str(tmpdir) chunkSize = 4 chunkedStore = ChunkedFileStore(dbDir=dbDir, dbName="chunked_data", isLineNoKey=isLineNoKey, storeContentHash=storeContentHash, chunkSize=chunkSize, ensureDurability=ensureDurability) textStore = TextFileStore(dbDir=dbDir, dbName="text_data", isLineNoKey=isLineNoKey, storeContentHash=storeContentHash, ensureDurability=ensureDurability) for i in range(1, 5 * chunkSize): value = "Some data {}".format(str(i)) chunkedStore.put(None, value) textStore.put(None, value) assert textStore.get(str(i)) assert textStore.get(str(i)) == chunkedStore.get(str(i)) assert list(chunkedStore.iterator()) == \ list(textStore.iterator())
def create_ledger_text_file_storage(txn_serializer, hash_serializer, tempdir, init_genesis_txn_file=None): if isinstance(txn_serializer, MsgPackSerializer): # MsgPack is a binary one, not compatible with TextFileStorage store = BinarySerializerBasedFileStore(txn_serializer, tempdir, 'transactions', isLineNoKey=True, storeContentHash=False, ensureDurability=False) else: store = TextFileStore(tempdir, 'transactions', isLineNoKey=True, storeContentHash=False, ensureDurability=False) return __create_ledger(store, txn_serializer, hash_serializer, tempdir, init_genesis_txn_file)
def getLedger(baseDir, dbName, storeHash=True, isLineNoKey: bool = False): return TextFileStore(dbDir=baseDir, dbName=dbName, storeContentHash=storeHash, isLineNoKey=isLineNoKey)
def default_chunk_creator(name): return TextFileStore(self.dataDir, name, isLineNoKey, storeContentHash, ensureDurability)
def initStorage(storageType, name, dataDir=None, config=None): if storageType == StorageType.File: if dataDir is None: raise DataDirectoryNotFound return TextFileStore(dataDir, name)