Repository navigation
Conversation
JackieTien97
left a comment
There was a problem hiding this comment.
I verified the fix for #1187 with an IoTDB insert, flush, and readback. Editing the first row preserved the value 80 in the second row. I’m requesting changes because a timestamp-only write can still persist a stale value, editing an active row can now throw with a trimmed bitmap, and two tablet-building workloads regressed in JMH. The inline comments include the reproductions and measurements against 42168eae.
|
|
||
| maxRowNumber = Math.max(preferredCapacity, Math.max(maxRowNumber, rowSize + another.rowSize)); | ||
| rowSize = rowSize + another.rowSize; | ||
| int firstReservedRow = Math.max(prevCapacity, rowSize); |
There was a problem hiding this comment.
[P1] Use the previous logical capacity when marking reserved rows. IoTDB’s SessionUtils.filterNullColumns reuses the backing arrays and passes the active row count to the Tablet constructor. I reproduced this with two active rows, arrays of length eight, and 733 left in value slot 3. After editing row 0 to enter AUTO, I appended one row with append(other, 8) and called only addTimestamp(3, 40). prevCapacity is eight, so this calculation skips the null mark for row 3. An IoTDB insertTablet, FLUSH, and query returned (40, 733). The same sequence on the base commit had no value at time 40.
Please capture maxRowNumber before updating it and use the old logical capacity together with the post-append row count to identify the newly reserved rows. A regression test with oversized backing arrays would catch this silent write. IoTDB caller
| if (firstNullRow == 0) { | ||
| bitMaps[i].markAll(); | ||
| } else { | ||
| bitMaps[i].markRange(firstNullRow, maxRowNumber - firstNullRow); |
There was a problem hiding this comment.
[P2] Handle bitmaps trimmed to the active row count. I deserialized a 64-row tablet, called setRowSize(2), and replaced the bitmap for its single column with oldMap.getRegion(0, 2). This tablet serializes successfully. On the base commit, addValue("s", 0, 71) produces [71, null]. Here the same edit calls markRange(2, 62) on a two-bit bitmap and throws IndexOutOfBoundsException while updating row 0.
Please extend an existing bitmap before marking beyond its size, or defer marking until the reserved rows are used. A test that trims both the row count and the bitmap before the first edit would cover this case.
| } | ||
|
|
||
| private void initBitMapsWithApiUsage() { | ||
| if (bitMapMode != BitMapMode.AUTO || bitMaps == null) { |
There was a problem hiding this comment.
[P2] Address the regression in name-based inserts on a reused tablet. IoTDB’s records-to-tablet conversion calls addTimestamp once per row and addValue(String, int, Object) for each measurement. I benchmarked that loop with reset() between batches, 1,024 rows × 16 INT32 columns, and one null per 16 cells. On an M2 Pro with JDK 21.0.8, single-threaded JMH measured 144.37 µs/batch on base and 153.42 µs/batch on this commit (+6.3%). I alternated revisions over five pairs of independent JVM forks with identical dependencies. All five PR forks were slower. The timed operation ends before RPC encoding.
Please profile the steady-state case with the bitmaps already initialized and recheck this workload after adjusting the fast path. IoTDB write loop
| rowSize = rowSize + another.rowSize; | ||
| int firstReservedRow = Math.max(prevCapacity, rowSize); | ||
| if (bitMapMode == BitMapMode.AUTO && firstReservedRow < maxRowNumber) { | ||
| initializeBitMapsFromRow(firstReservedRow); |
There was a problem hiding this comment.
[P2] Preserve sparse bitmaps when append only reserves capacity. After IoTDB compacts an API-filled tablet with no nulls, bitMaps can be null while the mode is still AUTO. Growing the tablet here allocates a full bitmap for every column, even when both input tablets contain only present values and the caller only needs to append.
I measured filling 16 rows × 64 BOOLEAN columns, compacting the bitmaps, and appending another 16 rows with preferred capacity 4,096. The workload allocated 37,136 extra bytes per batch. Across four independent JVM forks per revision on JDK 21, median time went from 18.04 to 21.23 µs/batch (+17.7%). Please defer bitmap allocation until a reserved row needs null flags and cover both append-only and timestamp-only writes. IoTDB bitmap compaction
| private enum BitMapMode { | ||
| DIRECT, | ||
| POPULATED, | ||
| AUTO | ||
| } |
There was a problem hiding this comment.
Better to add some comments explaining the behavior of each mode.
Use the previous logical capacity when growing existing bitmaps. Preserve values written ahead of their timestamps and extend trimmed maps before marking new rows. Keep omitted bitmaps sparse during append and avoid bitmap preparation on the normal API write path. Cover oversized backing arrays, trimmed and partially compacted bitmaps, and timestamp-only writes. Update the Java SDK reference. CLI behavior and the wire format are unchanged. Verified with JDK 21 and ./mvnw -P with-java clean verify (27 TabletTest cases). A TsFile write/readback retained values at times 10, 20 and 30 and yielded no stale point at time 40. Single-thread JMH, Apple M4, JDK 21.0.10, median of three forks. Name-based inserts took 160.87 / 174.32 / 144.47 us per batch on base / reviewed / fixed. Compact append took 14.47 / 17.69 / 14.78 us and allocated 306576 / 343712 / 306584 bytes per batch.
|
No additional comments besides the ones already put by JackieTien97. However, Tablet is initially designed as a data exchange structure, instead of a data processing structure, Some problems are also historical: the first version of Tablet makes its members public instead of exposing APIs. |
|
@jt2594838 @JackieTien97 thank review |
|
I've pushed the requested changes and would appreciate another review. Thanks! |
JackieTien97
left a comment
There was a problem hiding this comment.
Thanks for the updates! I verified that the oversized backing array case, trimmed bitmaps, compacted sparse append, and BitMapMode documentation are all resolved on 54137b51.
Requesting changes for two remaining issues:
getBitMaps()permanently setsbitMapsShared = true, which disables thebitMapsReadyfast path for all subsequent reused batches once a tablet has been written viaTsFileWriteror encoded by IoTDBSession.insertTablet(+34% to 14.4× regression depending onaddTimestamp/addValueorder).- The
@TsFileApireference-typedaddValue/addObjectPathValueoverloads (String,byte[],LocalDate, object path) still return early onnull, silently leaving the previous non-null value in place when editing a deserialized or populatedTablet.
| if (bitMaps != null) { | ||
| bitMapsShared = true; | ||
| bitMapsReady = false; | ||
| } |
There was a problem hiding this comment.
[P1] Avoid permanently disabling bitMapsReady when getBitMaps() is read during flushes or RPC encoding. Every TsFile write (AlignedChunkGroupWriterImpl / NonAlignedChunkGroupWriterImpl) and IoTDB Session insert (TabletEncoder.encodeBitMap / SessionUtils) calls tablet.getBitMaps() to inspect null flags before tablet.reset(). Setting bitMapsShared = true here is sticky for the rest of the tablet's lifetime, so both initializeBitMapsForWrite() (bitMapsReady = !bitMapsShared) and reset() (bitMapsReady = ... && !bitMapsShared) keep bitMapsReady == false on every subsequent batch:
- In the canonical
addTimestamp(r, ts)→addValue(r, c, intVal)→getBitMaps()→reset()loop (1,024rows ×32INT32columns, 3 alternating JVM runs),addTimestampseesrowIndex >= rowSizeon every row and scans all column bitmaps1,024times per batch whileupdateBitMapentersprepareColumnBitMapon every cell, regressing steady-state time from 88 µs/batch on42168eaeto 118 µs/batch on54137b51(+34%). - When values are written before their row timestamp (
addValue(curRow, c, intVal)→addTimestamp(curRow, ts)→getBitMaps()→reset(), as in IoTDB relational tablet routing atSession.java:3155-3161),rowIndex >= rowSizestaystruefor every cell in the row, invokinginitializeBitMapsForWrite()rows × (cols + 1)times (O(rows × cols²)), which regresses from 112 µs/batch on42168eaeto 1,613 µs/batch on54137b51(14.4× slower).
Clearing bitMapsReady = false in getBitMaps() / setBitMaps() without keeping a sticky bitMapsShared flag (so initializeBitMapsForWrite() and reset() can re-arm bitMapsReady = true once all column bitmaps are non-null and sized to maxRowNumber) still catches pre-write array edits like target.getBitMaps()[0] = ... while keeping reused tablets on the fast path.
| initBitMapsWithApiUsage(); | ||
| } | ||
|
|
||
| public void addValue(final String measurementId, final int rowIndex, final Object value) { |
There was a problem hiding this comment.
[P2] Mark null bitmaps in the @TsFileApi reference-typed addValue and addObjectPathValue overloads when val == null. addValue(String, int, Object) handles null via updateBitMap(rowIndex, indexOfSchema, value == null), but the @TsFileApi typed overloads—addValue(int, int, String) (L437), addObjectPathValue(int, int, String) (L459), addObjectPathValue(int, int, byte[]) (L478), addValue(int, int, byte[]) (L493), and addValue(int, int, LocalDate) (L513)—all do if (val == null) { return; }.
That early return only worked on fresh tablets whose bitmaps had already been marked all-null. On a deserialized or populated Tablet (including table-model callers using @TsFileApi), calling e.g. copy.addValue(0, 0, (String) null) or copy.addValue(0, 0, (LocalDate) null) neither transitions POPULATED → AUTO nor marks the cell null, silently retaining the old non-null value in row 0. When val == null (after validating the column type, including in addObjectPathValue(int, int, String)), please clear the slot (Binary.EMPTY_VALUE / DateType.EMPTY_DATE) and call updateBitMap(rowIndex, columnIndex, true).
|
thank review~~~ |
Fixes #1187
What changed
Keep the restored null bitmaps on the first
addValueoraddTimestampafterTablet.deserialize. A column with no nulls has no serialized bitmap, so the first edit creates an all-unmarked bitmap for that column. Fresh tablets still start with all cells marked null on first API use. Resetting a restored tablet before its first API edit still allows callers to refill the backing arrays directly.The change is confined to the Java SDK and leaves the serialized format unchanged.
Verification
[70, 80, null]to71produced[71, null, null]on42168eaeand[71, 80, null]with this change.NullPointerExceptionon the same baseline. With this change the result was[71, 80, 90].reset()../mvnw -P with-java clean verifybuild passed. All 21 tests inTabletTestpassed, including the four new regression tests.