use of com.alipay.sofa.jraft.storage.log.RocksDBSegmentLogStorage in project sofa-jraft by sofastack.
the class LogStorageBenchmark method main.
public static void main(final String[] args) {
String testPath = Paths.get(SystemPropertyUtil.get("user.dir"), "log_storage").toString();
System.out.println("Test log storage path: " + testPath);
int batchSize = 100;
int logSize = 16 * 1024;
int totalLogs = 1024 * 1024;
// LogStorage logStorage = new RocksDBLogStorage(testPath, new RaftOptions());
LogStorage logStorage = new RocksDBSegmentLogStorage(testPath, new RaftOptions());
LogStorageOptions opts = new LogStorageOptions();
opts.setConfigurationManager(new ConfigurationManager());
opts.setLogEntryCodecFactory(LogEntryV2CodecFactory.getInstance());
logStorage.init(opts);
new LogStorageBenchmark(logStorage, logSize, totalLogs, batchSize).doTest();
}
use of com.alipay.sofa.jraft.storage.log.RocksDBSegmentLogStorage in project sofa-jraft by sofastack.
the class RocksDBSegmentLogStorageTest method testTruncateChaos.
@Test
public void testTruncateChaos() throws Exception {
int times = 100;
int n = 100;
for (int i = 0; i < times; i++) {
this.logStorage.shutdown();
FileUtils.deleteDirectory(new File(this.path));
this.path = TestUtils.mkTempDir();
FileUtils.forceMkdir(new File(this.path));
this.logStorage = new RocksDBSegmentLogStorage(this.path, new RaftOptions(), 32, 256);
final LogStorageOptions opts = newLogStorageOptions();
this.logStorage.init(opts);
for (int j = 0; j < n; j++) {
this.logStorage.appendEntries(Arrays.asList(TestUtils.mockEntry(j, 1, ThreadLocalRandom.current().nextInt(180))));
}
int index = ThreadLocalRandom.current().nextInt(n);
boolean truncatePrefix = ThreadLocalRandom.current().nextBoolean();
if (truncatePrefix) {
this.logStorage.truncatePrefix(index);
for (int j = 0; j < n; j++) {
if (j < index) {
assertNull(this.logStorage.getEntry(j));
} else {
assertNotNull(this.logStorage.getEntry(j));
}
}
} else {
this.logStorage.truncateSuffix(index);
for (int j = 0; j < n; j++) {
if (j <= index) {
assertNotNull(this.logStorage.getEntry(j));
} else {
assertNull(this.logStorage.getEntry(j));
}
}
}
}
}
use of com.alipay.sofa.jraft.storage.log.RocksDBSegmentLogStorage in project sofa-jraft by sofastack.
the class RocksDBSegmentLogStorageTest method testTruncateSuffixWithDifferentValueSize.
@Test
public void testTruncateSuffixWithDifferentValueSize() throws Exception {
// shutdown the old one
this.logStorage.shutdown();
// Set value threshold to be 32 bytes.
this.logStorage = new RocksDBSegmentLogStorage(this.path, new RaftOptions(), 32, 64);
final LogStorageOptions opts = newLogStorageOptions();
this.logStorage.init(opts);
int term = 1;
for (int i = 0; i < 10; i++) {
this.logStorage.appendEntries(Arrays.asList(TestUtils.mockEntry(i, term, i)));
}
this.logStorage.appendEntries(Arrays.asList(TestUtils.mockEntry(10, term, 64)));
for (int i = 11; i < 20; i++) {
this.logStorage.appendEntries(Arrays.asList(TestUtils.mockEntry(i, term, i)));
}
for (int i = 0; i < 20; i++) {
assertNotNull(this.logStorage.getEntry(i));
}
assertEquals(((RocksDBSegmentLogStorage) this.logStorage).getLastSegmentFileForRead().getWrotePos(), 179);
this.logStorage.truncateSuffix(15);
for (int i = 0; i < 20; i++) {
if (i <= 15) {
assertNotNull(this.logStorage.getEntry(i));
} else {
assertNull(this.logStorage.getEntry(i));
}
}
assertEquals(((RocksDBSegmentLogStorage) this.logStorage).getLastSegmentFileForRead().getWrotePos(), 102);
this.logStorage.truncateSuffix(13);
for (int i = 0; i < 20; i++) {
if (i <= 13) {
assertNotNull(this.logStorage.getEntry(i));
} else {
assertNull(this.logStorage.getEntry(i));
}
}
assertEquals(((RocksDBSegmentLogStorage) this.logStorage).getLastSegmentFileForRead().getWrotePos(), 102);
this.logStorage.truncateSuffix(5);
for (int i = 0; i < 20; i++) {
if (i <= 5) {
assertNotNull(this.logStorage.getEntry(i));
} else {
assertNull(this.logStorage.getEntry(i));
}
}
assertNull(((RocksDBSegmentLogStorage) this.logStorage).getLastSegmentFileForRead());
this.logStorage.appendEntries(Arrays.asList(TestUtils.mockEntry(20, term, 10)));
assertNotNull(this.logStorage.getEntry(20));
}
Aggregations