-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathcloud_txn_delete_bitmap_cache.h
More file actions
132 lines (109 loc) · 5.91 KB
/
cloud_txn_delete_bitmap_cache.h
File metadata and controls
132 lines (109 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#pragma once
#include <mutex>
#include "cpp/lru_cache.h"
#include "storage/olap_common.h"
#include "storage/partial_update_info.h"
#include "storage/rowset/rowset.h"
#include "storage/tablet/tablet_meta.h"
#include "storage/txn/txn_manager.h"
#include "util/countdown_latch.h"
namespace doris {
// Record transaction related delete bitmaps using a lru cache.
class CloudTxnDeleteBitmapCache : public LRUCachePolicy {
public:
CloudTxnDeleteBitmapCache(size_t size_in_bytes);
~CloudTxnDeleteBitmapCache() override;
Status init();
Status get_tablet_txn_info(TTransactionId transaction_id, int64_t tablet_id,
RowsetSharedPtr* rowset, DeleteBitmapPtr* delete_bitmap,
RowsetIdUnorderedSet* rowset_ids, int64_t* txn_expiration,
std::shared_ptr<PartialUpdateInfo>* partial_update_info,
std::shared_ptr<PublishStatus>* publish_status,
TxnPublishInfo* previous_publish_info);
void set_tablet_txn_info(TTransactionId transaction_id, int64_t tablet_id,
DeleteBitmapPtr delete_bitmap, const RowsetIdUnorderedSet& rowset_ids,
RowsetSharedPtr rowset, int64_t txn_expirationm,
std::shared_ptr<PartialUpdateInfo> partial_update_info);
Status update_tablet_txn_info(TTransactionId transaction_id, int64_t tablet_id,
DeleteBitmapPtr delete_bitmap,
const RowsetIdUnorderedSet& rowset_ids,
PublishStatus publish_status, TxnPublishInfo publish_info = {});
void remove_expired_tablet_txn_info();
void remove_unused_tablet_txn_info(TTransactionId transaction_id, int64_t tablet_id);
// Mark a rowset as empty/skipped (lightweight marker, no rowset stored)
// Used for empty rowsets when skip_writing_empty_rowset_metadata is enabled
void mark_empty_rowset(TTransactionId txn_id, int64_t tablet_id, int64_t txn_expiration);
// Check if this is a known empty/skipped rowset
// Returns true if was marked as empty rowset
// Note: Does not remove the marker, as CalcDeleteBitmapTask may retry.
// Cleanup is handled by expiration-based removal in remove_expired_tablet_txn_info()
bool is_empty_rowset(TTransactionId txn_id, int64_t tablet_id);
// !!!ATTENTION!!!: the delete bitmap stored in CloudTxnDeleteBitmapCache contains sentinel marks,
// and the version in BitmapKey is DeleteBitmap::TEMP_VERSION_COMMON.
// when using delete bitmap from this cache, the caller should manually remove these marks if don't need it
// and should replace versions in BitmapKey by the correct version
Status get_delete_bitmap(TTransactionId transaction_id, int64_t tablet_id,
DeleteBitmapPtr* delete_bitmap, RowsetIdUnorderedSet* rowset_ids,
std::shared_ptr<PublishStatus>* publish_status);
// the caller should guarantee that the txn `transaction_id` has been published successfully in MS
Result<std::pair<RowsetSharedPtr, DeleteBitmapPtr>> get_rowset_and_delete_bitmap(
TTransactionId transaction_id, int64_t tablet_id);
private:
void _clean_thread_callback();
class DeleteBitmapCacheValue : public LRUCacheValueBase {
public:
DeleteBitmapPtr delete_bitmap;
// records rowsets calc in commit txn
RowsetIdUnorderedSet rowset_ids;
DeleteBitmapCacheValue(DeleteBitmapPtr delete_bitmap_, const RowsetIdUnorderedSet& ids_)
: delete_bitmap(std::move(delete_bitmap_)), rowset_ids(ids_) {}
};
struct TxnKey {
TTransactionId txn_id;
int64_t tablet_id;
TxnKey(TTransactionId txn_id_, int64_t tablet_id_)
: txn_id(txn_id_), tablet_id(tablet_id_) {}
auto operator<=>(const TxnKey&) const = default;
};
struct TxnVal {
RowsetSharedPtr rowset;
int64_t txn_expiration;
std::shared_ptr<PartialUpdateInfo> partial_update_info;
std::shared_ptr<PublishStatus> publish_status = nullptr;
// used to determine if the retry needs to re-calculate the delete bitmap
TxnPublishInfo publish_info;
TxnVal() : txn_expiration(0) {};
TxnVal(RowsetSharedPtr rowset_, int64_t txn_expiration_,
std::shared_ptr<PartialUpdateInfo> partial_update_info_,
std::shared_ptr<PublishStatus> publish_status_)
: rowset(std::move(rowset_)),
txn_expiration(txn_expiration_),
partial_update_info(std::move(partial_update_info_)),
publish_status(std::move(publish_status_)) {}
};
std::map<TxnKey, TxnVal> _txn_map;
std::multimap<int64_t, TxnKey> _expiration_txn;
// Lightweight markers for empty/skipped rowsets (only stores TxnKey, ~16 bytes per entry)
// Used to track empty rowsets that were not committed to meta-service
std::set<TxnKey> _empty_rowset_markers;
std::shared_mutex _rwlock;
std::shared_ptr<Thread> _clean_thread;
CountDownLatch _stop_latch;
};
} // namespace doris