Search in sources :

Example 6 with LogStorageOptions

use of com.alipay.sofa.jraft.option.LogStorageOptions 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));
}
Also used : RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) LogStorageOptions(com.alipay.sofa.jraft.option.LogStorageOptions) RocksDBSegmentLogStorage(com.alipay.sofa.jraft.storage.log.RocksDBSegmentLogStorage) Test(org.junit.Test)

Aggregations

LogStorageOptions (com.alipay.sofa.jraft.option.LogStorageOptions)6 RaftOptions (com.alipay.sofa.jraft.option.RaftOptions)4 ConfigurationManager (com.alipay.sofa.jraft.conf.ConfigurationManager)3 RocksDBSegmentLogStorage (com.alipay.sofa.jraft.storage.log.RocksDBSegmentLogStorage)3 LogStorage (com.alipay.sofa.jraft.storage.LogStorage)2 Test (org.junit.Test)2 FSMCaller (com.alipay.sofa.jraft.FSMCaller)1 Status (com.alipay.sofa.jraft.Status)1 Configuration (com.alipay.sofa.jraft.conf.Configuration)1 ConfigurationEntry (com.alipay.sofa.jraft.conf.ConfigurationEntry)1 NodeMetrics (com.alipay.sofa.jraft.core.NodeMetrics)1 EntryType (com.alipay.sofa.jraft.entity.EnumOutter.EntryType)1 ErrorType (com.alipay.sofa.jraft.entity.EnumOutter.ErrorType)1 LogEntry (com.alipay.sofa.jraft.entity.LogEntry)1 LogId (com.alipay.sofa.jraft.entity.LogId)1 PeerId (com.alipay.sofa.jraft.entity.PeerId)1 SnapshotMeta (com.alipay.sofa.jraft.entity.RaftOutter.SnapshotMeta)1 LogEntryCorruptedException (com.alipay.sofa.jraft.error.LogEntryCorruptedException)1 RaftError (com.alipay.sofa.jraft.error.RaftError)1 RaftException (com.alipay.sofa.jraft.error.RaftException)1