diff --git a/be/src/olap/data_dir.h b/be/src/olap/data_dir.h index cde3d81541ac53..b8899c38d474fa 100644 --- a/be/src/olap/data_dir.h +++ b/be/src/olap/data_dir.h @@ -94,6 +94,10 @@ class DataDir { return _id_generator->get_next_id(id); } + OLAPStatus set_next_id(RowsetId new_rowset_id) { + return _id_generator->set_next_id(new_rowset_id); + } + // load data from meta and data files OLAPStatus load(); diff --git a/be/src/olap/rowset/rowset_id_generator.cpp b/be/src/olap/rowset/rowset_id_generator.cpp index 85157964853b4d..55aca7f05253b7 100644 --- a/be/src/olap/rowset/rowset_id_generator.cpp +++ b/be/src/olap/rowset/rowset_id_generator.cpp @@ -53,7 +53,23 @@ OLAPStatus RowsetIdGenerator::get_next_id(RowsetId* gen_rowset_id) { return s; } } - *gen_rowset_id = _next_id++; + *gen_rowset_id = _next_id; + ++_next_id; + return OLAP_SUCCESS; +} + +OLAPStatus RowsetIdGenerator::set_next_id(RowsetId new_rowset_id) { + std::lock_guard l(_lock); + // must be < not <= + if (new_rowset_id < _next_id) { + return OLAP_SUCCESS; + } + if (new_rowset_id >= _id_batch_end) { + _id_batch_end = new_rowset_id + k_batch_interval; + auto s = _meta->put(DEFAULT_COLUMN_FAMILY_INDEX, END_ROWSET_ID, std::to_string(_id_batch_end)); + RETURN_NOT_OK(s); + } + _next_id = new_rowset_id + 1; return OLAP_SUCCESS; } diff --git a/be/src/olap/rowset/rowset_id_generator.h b/be/src/olap/rowset/rowset_id_generator.h index b92d069dfcee31..c6a1436713a3c7 100644 --- a/be/src/olap/rowset/rowset_id_generator.h +++ b/be/src/olap/rowset/rowset_id_generator.h @@ -41,6 +41,8 @@ class RowsetIdGenerator { // it saves the batch end id into meta env OLAPStatus get_next_id(RowsetId* rowset_id); + OLAPStatus set_next_id(RowsetId new_rowset_id); + private: OlapMeta* _meta = nullptr; diff --git a/be/src/olap/snapshot_manager.cpp b/be/src/olap/snapshot_manager.cpp index 25d34b0c601193..d81d0bd33f2e41 100644 --- a/be/src/olap/snapshot_manager.cpp +++ b/be/src/olap/snapshot_manager.cpp @@ -155,6 +155,28 @@ OLAPStatus SnapshotManager::convert_rowset_ids(DataDir& data_dir, const string& new_tablet_meta_pb.set_schema_hash(schema_hash); TabletSchema tablet_schema; RETURN_NOT_OK(tablet_schema.init_from_pb(new_tablet_meta_pb.schema())); + + RowsetId max_rowset_id = 0; + for (auto& visible_rowset : cloned_tablet_meta_pb.rs_metas()) { + if (visible_rowset.rowset_id() > max_rowset_id) { + max_rowset_id = visible_rowset.rowset_id(); + } + } + + for (auto& inc_rowset : cloned_tablet_meta_pb.inc_rs_metas()) { + if (inc_rowset.rowset_id() > max_rowset_id) { + max_rowset_id = inc_rowset.rowset_id(); + } + } + RowsetId next_rowset_id = 0; + RETURN_NOT_OK(data_dir.next_id(&next_rowset_id)); + if (next_rowset_id <= max_rowset_id) { + OLAPStatus set_id_st = data_dir.set_next_id(max_rowset_id + 1); + if (set_id_st != OLAP_SUCCESS) { + return set_id_st; + } + } + for (auto& visible_rowset : cloned_tablet_meta_pb.rs_metas()) { RowsetMetaPB* rowset_meta = new_tablet_meta_pb.add_rs_metas(); RETURN_NOT_OK(_rename_rowset_id(visible_rowset, clone_dir, data_dir, tablet_schema, rowset_meta)); diff --git a/be/src/olap/txn_manager.cpp b/be/src/olap/txn_manager.cpp index f3bd4abd3b14c5..3816ea115097a4 100755 --- a/be/src/olap/txn_manager.cpp +++ b/be/src/olap/txn_manager.cpp @@ -113,7 +113,7 @@ OLAPStatus TxnManager::prepare_txn( // case 2: loading txn from meta env TabletTxnInfo load_info(load_id, nullptr); _txn_tablet_map[key][tablet_info] = load_info; - VLOG(3) << "add transaction to engine successfully." + LOG(INFO) << "add transaction to engine successfully." << "partition_id: " << key.first << ", transaction_id: " << key.second << ", tablet: " << tablet_info.to_string(); @@ -189,7 +189,7 @@ OLAPStatus TxnManager::commit_txn( WriteLock wrlock(&_txn_map_lock); TabletTxnInfo load_info(load_id, rowset_ptr); _txn_tablet_map[key][tablet_info] = load_info; - VLOG(3) << "add transaction to engine successfully." + LOG(INFO) << "add transaction to engine successfully." << "partition_id: " << key.first << ", transaction_id: " << key.second << ", tablet: " << tablet_info.to_string();