Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dynamic Region] An empty snapshot may still create segment #8089

Closed
CalvinNeo opened this issue Sep 13, 2023 · 3 comments · Fixed by #8199
Closed

[Dynamic Region] An empty snapshot may still create segment #8089

CalvinNeo opened this issue Sep 13, 2023 · 3 comments · Fixed by #8199

Comments

@CalvinNeo
Copy link
Member

CalvinNeo commented Sep 13, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

The problem is in raftstore v1, after a table is truncated, the snapshot of the new table is not sent to TiFlash or not being handled.
However, in raftstore v2, the snapshot is handled by TiFlash, thus result in a empty segment.

Some intergrated tests like alter_truncated_table.test may fail.

[2023/09/12 23:41:17.503 +08:00] [INFO] [SSTReader.h:119] ["Open sst file first !/DATA/disk4/luorongzhen/tidb-data/tiflash-5761/flash/snap_v2/rev_136_138_6_7 range [7480000000000000FF685F720000000000FA,7480000000000000FF6900000000000000F8]"] [source="keyspace=4294967295 table_id=104"] [thread_id=273]
[2023/09/12 23:41:17.505 +08:00] [INFO] [SSTReader.cpp:82] ["Seek cf Default to 7480000000000000FF685F720000000000FA"] [source=MonoSSTReader] [thread_id=273]
[2023/09/12 23:41:17.505 +08:00] [INFO] [SSTReader.h:119] ["Open sst file first !/DATA/disk4/luorongzhen/tidb-data/tiflash-5761/flash/snap_v2/rev_136_138_6_7 range [7480000000000000FF685F720000000000FA,7480000000000000FF6900000000000000F8]"] [source="keyspace=4294967295 table_id=104"] [thread_id=273]
[2023/09/12 23:41:17.508 +08:00] [INFO] [SSTReader.cpp:82] ["Seek cf Write to 7480000000000000FF685F720000000000FA"] [source=MonoSSTReader] [thread_id=273]
[2023/09/12 23:41:17.509 +08:00] [INFO] [SSTReader.h:119] ["Open sst file first !/DATA/disk4/luorongzhen/tidb-data/tiflash-5761/flash/snap_v2/rev_136_138_6_7 range [7480000000000000FF685F720000000000FA,7480000000000000FF6900000000000000F8]"] [source="keyspace=4294967295 table_id=104"] [thread_id=273]
[2023/09/12 23:41:17.512 +08:00] [INFO] [SSTReader.cpp:82] ["Seek cf Lock to 7480000000000000FF685F720000000000FA"] [source=MonoSSTReader] [thread_id=273]
[2023/09/12 23:41:17.512 +08:00] [INFO] [SSTFilesToBlockInputStream.cpp:128] ["Finish Construct MultiSSTReader, write=1 lock=1 default=1 region_id=136"] [source="keyspace=4294967295 table_id=104"] [thread_id=273]
[2023/09/12 23:41:17.512 +08:00] [DEBUG] [SSTFilesToBlockInputStream.cpp:239] ["Done loading all kvpairs from [CF=default] [offset=0] [write_cf_offset=0] [region_id=136]"] [source="keyspace=4294967295 table_id=104"] [thread_id=273]
[2023/09/12 23:41:17.512 +08:00] [DEBUG] [SSTFilesToBlockInputStream.cpp:239] ["Done loading all kvpairs from [CF=lock] [offset=0] [write_cf_offset=0] [region_id=136]"] [source="keyspace=4294967295 table_id=104"] [thread_id=273]
[2023/09/12 23:41:17.512 +08:00] [INFO] [SSTFilesToDTFilesOutputStream.cpp:129] ["Transformed snapshot in SSTFile to DTFiles, region=[region_id=136 applied_term=6 applied_index=7] job_type=ApplySnapshot cost_ms=0 rows=0 bytes=0 bytes_on_disk=0 write_cf_keys=0 default_cf_keys=0 lock_cf_keys=0 dt_files=[files_num=0 ]"] [source="keyspace=4294967295 table_id=104"] [thread_id=273]
[2023/09/12 23:41:17.512 +08:00] [DEBUG] [DMVersionFilterBlockInputStream.h:83] ["Total rows: 0, pass: -nan%, complete pass: -nan%, complete not pass: -nan%, not clean: -nan%, is deleted: -nan%, effective: -nan%, start_ts: 0"] [source="mode=COMPACT"] [thread_id=273]
[2023/09/12 23:41:17.512 +08:00] [INFO] [Region.cpp:661] ["After prehandle, remains orphan keys 0 removed orphan keys 0 [region_id=136]"] [thread_id=273]
[2023/09/12 23:41:17.591 +08:00] [INFO] [ApplySnapshot.cpp:500] ["Begin apply snapshot, new_region=[region_id=136 applied_term=6 applied_index=7]"] [thread_id=267]
[2023/09/12 23:41:17.591 +08:00] [INFO] [DeltaMergeStore_Ingest.cpp:711] ["Table ingest files - begin, use_split_replace=false files=[] rows=0 bytes=0 bytes_on_disk=0 range=[-9223372036854775808,9223372036854775807) clear=true"] [source="keyspace=4294967295 table_id=104"] [thread_id=267]
[2023/09/12 23:41:17.591 +08:00] [INFO] [DeltaMergeStore.cpp:2141] ["creating the first segment with segment_id=1"] [source="keyspace=4294967295 table_id=104"] [thread_id=267]
[2023/09/12 23:41:17.591 +08:00] [TRACE] [WriteBatchesImpl.h:105] ["Write into data : E104.1"] [thread_id=267]
[2023/09/12 23:41:17.592 +08:00] [TRACE] [WriteBatchesImpl.h:215] ["Write into meta : 104.3,104.2,104.3,104.1"] [thread_id=267]
[2023/09/12 23:41:17.592 +08:00] [TRACE] [Segment.cpp:646] ["Segment ingest data to delta, range=[-9223372036854775808,9223372036854775807) clear=true"] [source="keyspace=4294967295 table_id=104 segment_id=1 epoch=0"] [thread_id=267]
[2023/09/12 23:41:17.592 +08:00] [INFO] [DeltaMergeStore_Ingest.cpp:801] ["Table ingest files - finished ingested files into segments, ingested_files=[] updated_segments=[<segment_id=1 epoch=0 range=[-9223372036854775808,9223372036854775807)>] clear=true"] [source="keyspace=4294967295 table_id=104"] [thread_id=267]
[2023/09/12 23:41:17.592 +08:00] [DEBUG] [DeltaValueSpace.cpp:323] ["Flush start, delta=MemTableSet: 1 column files, 0 rows, 0 bytes, 1 deletes. ColumnFilePersistedSet [2]: 0 column files, 0 rows, 0 bytes, 0 deletes."] [source="keyspace=4294967295 table_id=104 segment_id=1 epoch=0"] [thread_id=267]
[2023/09/12 23:41:17.592 +08:00] [TRACE] [WriteBatchesImpl.h:215] ["Write into meta : 104.2"] [thread_id=267]
[2023/09/12 23:41:17.592 +08:00] [DEBUG] [ColumnFilePersistedSet.cpp:268] ["ColumnFilePersistedSet [2]: 1 column files, 0 rows, 0 bytes, 1 deletes., after append 1 column files, persisted column files: [D_[-9223372036854775808,9223372036854775807)]"] [source="keyspace=4294967295 table_id=104 segment_id=1 epoch=0"] [thread_id=267]
[2023/09/12 23:41:17.592 +08:00] [DEBUG] [DeltaValueSpace.cpp:401] ["Flush end, flush_tasks=1 flush_rows=0 flush_deletes=1 delta=MemTableSet: 0 column files, 0 rows, 0 bytes, 0 deletes. ColumnFilePersistedSet [2]: 1 column files, 0 rows, 0 bytes, 1 deletes."] [source="keyspace=4294967295 table_id=104 segment_id=1 epoch=0"] [thread_id=267]
[2023/09/12 23:41:17.592 +08:00] [INFO] [RegionTable.cpp:49] ["get new table, keyspace=4294967295 table_id=104"] [thread_id=267]
[2023/09/12 23:41:17.592 +08:00] [INFO] [RegionTable.cpp:394] ["insert internal region, keyspace=4294967295 table_id=104 region_id=136"] [thread_id=267]
[2023/09/12 23:41:17.592 +08:00] [INFO] [KVStore.cpp:410] ["Start to persist [region_id=136 applied_term=6 applied_index=7], cache size: 0 bytes for `save current region after apply `"] [thread_id=267]
[2023/09/12 23:41:17.594 +08:00] [DEBUG] [KVStore.cpp:412] ["Persist [region_id=136] done"] [thread_id=267]
[2023/09/12 23:41:17.594 +08:00] [INFO] [ApplySnapshot.cpp:512] ["Finish apply snapshot, cost=0.004s region_id=136"] [thread_id=267]

1. Minimal reproduce step (Required)

2. What did you expect to see? (Required)

3. What did you see instead (Required)

4. What is your TiFlash version? (Required)

@CalvinNeo CalvinNeo added the type/bug The issue is confirmed as a bug. label Sep 13, 2023
@jebter
Copy link

jebter commented Sep 21, 2023

/component storage
/severity major

@CalvinNeo
Copy link
Member Author

The problem is snap.len in the following codes in raftstore v2 is always 3, even if the snapshot is actually empty.

PrehandleResult KVStore::preHandleSSTsToDTFiles(
    RegionPtr new_region,
    const SSTViewVec snaps,
    uint64_t index,
    uint64_t term,
    DM::FileConvertJobType job_type,
    TMTContext & tmt)
{
    // if it's only a empty snapshot, we don't create the Storage object, but return directly.
    if (snaps.len == 0)
    {
        return {};
    }

As a consequence, the schea sync process in KVStore::preHandleSSTsToDTFiles will always be triggered, leading to InterpreterCreateQuery::createTable -> DatabaseTiFlash::createTable

@CalvinNeo
Copy link
Member Author

We can create three cf readers, and use seekToFirst + remains to check if it is an empty snapshot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants