use of com.swirlds.virtualmap.datasource.VirtualLeafRecord in project hedera-services by hashgraph.
the class UpdateBench method updateLeavesAndInternals.
@Benchmark
public void updateLeavesAndInternals(DatabaseMergingState databaseState) throws IOException {
var internalRecordStream = IntStream.range(0, NUMBER_OF_INTERNALS_CHANGED_PER_FLUSH).mapToObj(i -> new VirtualInternalRecord(randomInternalPaths[i], hash((int) randomInternalPaths[i])));
var leafRecordStream = IntStream.range(0, NUMBER_OF_LEAVES_CHANGED_PER_FLUSH).mapToObj(i -> {
final long path = randomLeafPaths[i];
return new VirtualLeafRecord<>(path, hash((int) path), new ContractKey(path, path), new ContractValue(path));
});
databaseState.dataSource.saveRecords(databaseState.dataSource.getFirstLeafPath(), databaseState.dataSource.getLastLeafPath(), internalRecordStream, leafRecordStream, Stream.empty());
}
use of com.swirlds.virtualmap.datasource.VirtualLeafRecord in project hedera-services by hashgraph.
the class ThorsFileHammer method updateAllValues.
public void updateAllValues() {
try {
final int batchSize = 1000;
final int numOfBatches = (int) ((fileCollection.getMaximumValidKey() - fileCollection.getMinimumValidKey()) / batchSize);
System.out.println("ThorsHammer.updateAllValues numOfBatches=" + numOfBatches);
for (int batchIndex = 0; batchIndex < numOfBatches; batchIndex++) {
final int firstLeaf = (int) (fileCollection.getMinimumValidKey() + (batchIndex * batchSize));
final int lastLeaf = firstLeaf + batchSize;
final var leafRecordStream = LongStream.range(firstLeaf, lastLeaf).mapToObj(path -> new VirtualLeafRecord<>(path, hash((int) path), new ContractKey(path / 1000, path), new ContractValue(RANDOM.nextLong()))).peek(leaf -> compareToMe.set((int) leaf.getPath(), (int) leaf.getValue().asLong()));
try {
readWriteLock.writeLock().lock();
fileCollection.startWriting();
final Map<Long, Long> indexUpdates = new HashMap<>();
leafRecordStream.forEach(leaf -> {
try {
indexUpdates.put(leaf.getPath(), fileCollection.storeDataItem(leaf));
} catch (IOException e) {
e.printStackTrace();
}
});
final var dataFile = fileCollection.endWriting(fileCollection.getMinimumValidKey(), fileCollection.getMaximumValidKey());
for (var update : indexUpdates.entrySet()) {
index.put(update.getKey(), update.getValue());
}
dataFile.setFileAvailableForMerging(true);
} finally {
readWriteLock.writeLock().unlock();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
use of com.swirlds.virtualmap.datasource.VirtualLeafRecord in project hedera-services by hashgraph.
the class ThorsHammer method updateAllValues.
public void updateAllValues() {
try {
final int batchSize = 1000;
final int numOfBatches = (int) ((dataSource.getLastLeafPath() - dataSource.getFirstLeafPath()) / batchSize);
System.out.println("ThorsHammer.updateAllValues numOfBatches=" + numOfBatches);
for (int batchIndex = 0; batchIndex < numOfBatches; batchIndex++) {
final int firstLeaf = (int) (dataSource.getFirstLeafPath() + (batchIndex * batchSize));
final int lastLeaf = firstLeaf + batchSize;
readExclusionZoneFirstLeafPath.set(firstLeaf);
readExclusionZoneLastLeafPath.set(lastLeaf);
final var leafRecordStream = LongStream.range(firstLeaf, lastLeaf).mapToObj(path -> new VirtualLeafRecord<>(path, hash((int) path), new ContractKey(path / 1000, path), new ContractValue(RANDOM.nextLong()))).peek(leaf -> compareToMe.set((int) leaf.getPath(), (int) leaf.getValue().asLong()));
// try {
// readWriteLock.writeLock().lock();
dataSource.saveRecords(dataSource.getFirstLeafPath(), dataSource.getLastLeafPath(), Stream.empty(), leafRecordStream, Stream.empty());
// } finally {
// readWriteLock.writeLock().unlock();
// }
Thread.sleep(5);
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
use of com.swirlds.virtualmap.datasource.VirtualLeafRecord in project hedera-services by hashgraph.
the class VirtualDataSourceBench method setup.
@Setup(Level.Trial)
public void setup() throws IOException {
random = new Random(1234);
System.out.println("dataSourcePath = " + dataSourcePath);
if (Files.exists(dataSourcePath)) {
System.err.println("!!!!!!!!!!!!! Deleting old db.");
deleteDirectoryAndContents(dataSourcePath);
}
if (Files.exists(dataSourceSnapshotPath)) {
System.err.println("!!!!!!!!!!!!! Deleting old db snapshot.");
deleteDirectoryAndContents(dataSourceSnapshotPath);
}
// create data source
VirtualLeafRecordSerializer<ContractKey, ContractValue> virtualLeafRecordSerializer = new VirtualLeafRecordSerializer<>((short) 1, DigestType.SHA_384, (short) 1, DataFileCommon.VARIABLE_DATA_SIZE, new ContractKeySupplier(), (short) 1, ContractValue.SERIALIZED_SIZE, new ContractValueSupplier(), true);
JasperDbBuilder<ContractKey, ContractValue> dbBuilder = new JasperDbBuilder<>();
dbBuilder.virtualLeafRecordSerializer(virtualLeafRecordSerializer).virtualInternalRecordSerializer(new VirtualInternalRecordSerializer()).keySerializer(new ContractKeySerializer()).storageDir(dataSourcePath).maxNumOfKeys(500_000_000).preferDiskBasedIndexes(false).internalHashesRamToDiskThreshold(0).mergingEnabled(false);
dataSource = dbBuilder.build("jdb", "4dsBench");
// populate with initial data
System.out.printf("Creating initial data set of %,d leaves\n", initialDataSize);
progressPercentage = 0;
final long firstLeafPath = initialDataSize;
final long lastLeafPath = firstLeafPath + initialDataSize;
var internalRecordStream = LongStream.range(0, firstLeafPath).mapToObj(path -> new VirtualInternalRecord(path, hash((int) path)));
var leafRecordStream = LongStream.range(firstLeafPath, lastLeafPath + 1).mapToObj(path -> new VirtualLeafRecord<>(path, hash((int) path), new ContractKey(path, path), new ContractValue(path))).peek(leaf -> printProgress(leaf.getPath(), lastLeafPath));
dataSource.saveRecords(firstLeafPath, lastLeafPath, internalRecordStream, leafRecordStream, Stream.empty());
System.out.printf("Done creating initial data set of %,d leaves\n", initialDataSize);
}
use of com.swirlds.virtualmap.datasource.VirtualLeafRecord in project hedera-services by hashgraph.
the class VirtualDataSourceNewAPIBench method w3_add10kLeafValues.
/**
* Updates the first 10k leaves with new random values
*/
@Benchmark
public void w3_add10kLeafValues() throws Exception {
dataSource.saveRecords(numEntities, numEntities * 2, Stream.empty(), LongStream.range(nextPath, nextPath + 10_000).mapToObj(i -> new VirtualLeafRecord<>(i + numEntities, hash((int) i), new ContractKey(i, i), new ContractValue(i))), Stream.empty());
nextPath += 10_000;
}
Aggregations