|
59 | 59 | import org.apache.fluss.server.kv.rowmerger.RowMerger; |
60 | 60 | import org.apache.fluss.server.kv.scan.OpenScanResult; |
61 | 61 | import org.apache.fluss.server.kv.scan.ScannerContext; |
| 62 | +import org.apache.fluss.server.kv.snapshot.TabletState; |
62 | 63 | import org.apache.fluss.server.log.FetchIsolation; |
63 | 64 | import org.apache.fluss.server.log.LogAppendInfo; |
64 | 65 | import org.apache.fluss.server.log.LogTablet; |
@@ -1861,6 +1862,40 @@ void testRowCountWithMixedOperations() throws Exception { |
1861 | 1862 | kvTablet.close(); |
1862 | 1863 | } |
1863 | 1864 |
|
| 1865 | + @Test |
| 1866 | + void testFlushDoesNotRegressFlushedLogOffset() throws Exception { |
| 1867 | + initLogTabletAndKvTablet(DATA1_SCHEMA_PK, new HashMap<>()); |
| 1868 | + |
| 1869 | + List<KvRecord> inserts = new ArrayList<>(); |
| 1870 | + for (int i = 1; i <= 5; i++) { |
| 1871 | + inserts.add(kvRecordFactory.ofRecord("key" + i, new Object[] {i, "val" + i})); |
| 1872 | + } |
| 1873 | + kvTablet.putAsLeader(kvRecordBatchFactory.ofRecords(inserts), null); |
| 1874 | + |
| 1875 | + List<KvRecord> deletes = new ArrayList<>(); |
| 1876 | + for (int i = 1; i <= 2; i++) { |
| 1877 | + deletes.add(kvRecordFactory.ofRecord("key" + i, null)); |
| 1878 | + } |
| 1879 | + kvTablet.putAsLeader(kvRecordBatchFactory.ofRecords(deletes), null); |
| 1880 | + |
| 1881 | + long highOffset = logTablet.localLogEndOffset(); |
| 1882 | + kvTablet.flush(highOffset, NOPErrorHandler.INSTANCE); |
| 1883 | + TabletState stateAfterHighFlush = kvTablet.getTabletState(); |
| 1884 | + assertThat(stateAfterHighFlush.getFlushedLogOffset()).isEqualTo(highOffset); |
| 1885 | + assertThat(stateAfterHighFlush.getRowCount()).isEqualTo(3L); |
| 1886 | + assertThat(kvTablet.getRowCount()).isEqualTo(3); |
| 1887 | + |
| 1888 | + long lowOffset = highOffset - 2; |
| 1889 | + kvTablet.flush(lowOffset, NOPErrorHandler.INSTANCE); |
| 1890 | + TabletState stateAfterLowFlush = kvTablet.getTabletState(); |
| 1891 | + |
| 1892 | + assertThat(stateAfterLowFlush.getFlushedLogOffset()).isEqualTo(highOffset); |
| 1893 | + assertThat(stateAfterLowFlush.getRowCount()).isEqualTo(3L); |
| 1894 | + assertThat(kvTablet.getRowCount()).isEqualTo(3); |
| 1895 | + |
| 1896 | + kvTablet.close(); |
| 1897 | + } |
| 1898 | + |
1864 | 1899 | @Test |
1865 | 1900 | void testOpenScan_emptyBucket_returnsNullContext() throws Exception { |
1866 | 1901 | initLogTabletAndKvTablet(DATA1_SCHEMA_PK, new HashMap<>()); |
|
0 commit comments