@@ -123,8 +123,7 @@ class TieredStorage::ShardOpManager : public tiering::OpManager {
123
123
}
124
124
}
125
125
126
- bool NotifyFetched (EntryId id, string_view value, tiering::DiskSegment segment,
127
- bool modified) override ;
126
+ bool NotifyFetched (EntryId id, tiering::DiskSegment segment, tiering::Decoder* decoder) override ;
128
127
129
128
bool NotifyDelete (tiering::DiskSegment segment) override ;
130
129
@@ -210,12 +209,12 @@ void TieredStorage::ShardOpManager::Defragment(tiering::DiskSegment segment, str
210
209
}
211
210
}
212
211
213
- bool TieredStorage::ShardOpManager::NotifyFetched (EntryId id, string_view value ,
214
- tiering::DiskSegment segment, bool modified ) {
212
+ bool TieredStorage::ShardOpManager::NotifyFetched (EntryId id, tiering::DiskSegment segment ,
213
+ tiering::Decoder* decoder ) {
215
214
++stats_.total_fetches ;
216
215
217
216
if (id == EntryId{kFragmentedBin }) { // Generally we read whole bins only for defrag
218
- Defragment (segment, value);
217
+ // Defragment(segment, value);
219
218
return true ; // delete
220
219
}
221
220
@@ -224,20 +223,20 @@ bool TieredStorage::ShardOpManager::NotifyFetched(EntryId id, string_view value,
224
223
// Currently, our heuristic is not very smart, because we stop uploading any reads during
225
224
// the snapshotting.
226
225
// TODO: to revisit this when we rewrite it with more efficient snapshotting algorithm.
227
- bool should_upload = modified;
228
- should_upload |=
229
- (ts_-> UploadBudget () > int64_t (value. length ())) && !SliceSnapshot::IsSnaphotInProgress ();
226
+ bool should_upload = decoder-> modified ;
227
+ should_upload |= (ts_-> UploadBudget () > int64_t (decoder-> estimated_mem_usage )) &&
228
+ !SliceSnapshot::IsSnaphotInProgress ();
230
229
231
230
if (!should_upload)
232
231
return false ;
233
232
234
233
auto key = get<OpManager::KeyRef>(id);
235
234
auto * pv = Find (key);
236
235
if (pv && pv->IsExternal () && segment == pv->GetExternalSlice ()) {
237
- if (modified || pv->WasTouched ()) {
238
- bool is_raw = !modified;
236
+ if (decoder->modified || pv->WasTouched ()) {
239
237
++stats_.total_uploads ;
240
- Upload (key.first , value, is_raw, segment.length , pv);
238
+ decoder->Upload (pv);
239
+ // Upload(key.first, value, is_raw, segment.length, pv);
241
240
return true ;
242
241
}
243
242
pv->SetTouched (true );
@@ -262,11 +261,11 @@ bool TieredStorage::ShardOpManager::NotifyDelete(tiering::DiskSegment segment) {
262
261
if (bin.fragmented ) {
263
262
// Trigger read to signal need for defragmentation. NotifyFetched will handle it.
264
263
DVLOG (2 ) << " Enqueueing bin defragmentation for: " << bin.segment .offset ;
265
- auto cb = [dummy = 5 ](auto res) -> bool {
266
- (void )dummy; // a hack to make cb non constexpr that confuses some old) compilers.
267
- return false ;
268
- };
269
- Enqueue (kFragmentedBin , bin.segment , std::move (cb));
264
+ // auto cb = [dummy = 5](auto res) -> bool {
265
+ // (void)dummy; // a hack to make cb non constexpr that confuses some old) compilers.
266
+ // return false;
267
+ // };
268
+ // Enqueue(kFragmentedBin, bin.segment, std::move(cb));
270
269
}
271
270
272
271
return false ;
@@ -324,14 +323,11 @@ void TieredStorage::Read(DbIndex dbid, std::string_view key, const PrimeValue& v
324
323
std::function<void (io::Result<std::string>)> readf) {
325
324
DCHECK (value.IsExternal ());
326
325
DCHECK (!value.IsCool ());
327
- auto cb = [readf = std::move (readf), enc = value.GetStrEncoding ()](auto res) mutable {
328
- readf (res.transform ([enc](tiering::OpManager::FetchedEntry entry) {
329
- auto [ptr, raw] = entry;
330
- return raw ? enc.Decode (*ptr).Take () : *ptr; // TODO(vlad): optimize last value copy
331
- }));
332
- return false ;
326
+ auto cb = [readf = std::move (readf)](io::Result<tiering::StringDecoder*> res) mutable {
327
+ readf (res.transform ([](auto * d) { return string{d->Read ()}; }));
333
328
};
334
- op_manager_->Enqueue (KeyRef (dbid, key), value.GetExternalSlice (), std::move (cb));
329
+ op_manager_->Enqueue (KeyRef (dbid, key), value.GetExternalSlice (), tiering::StringDecoder{value},
330
+ std::move (cb));
335
331
}
336
332
337
333
template <typename T>
@@ -341,21 +337,11 @@ TieredStorage::TResult<T> TieredStorage::Modify(DbIndex dbid, std::string_view k
341
337
DCHECK (value.IsExternal ());
342
338
343
339
util::fb2::Future<io::Result<T>> future;
344
- auto cb = [future, modf = std::move (modf), enc = value.GetStrEncoding ()](auto res) mutable {
345
- if (!res.has_value ()) {
346
- future.Resolve (res.get_unexpected ());
347
- return false ;
348
- }
349
-
350
- auto [raw_val, is_raw] = *res;
351
- if (is_raw) {
352
- raw_val->resize (enc.DecodedSize (*raw_val));
353
- enc.Decode (*raw_val, raw_val->data ());
354
- }
355
- future.Resolve (modf (raw_val));
356
- return true ;
340
+ auto cb = [future, modf = std::move (modf)](io::Result<tiering::StringDecoder*> res) mutable {
341
+ future.Resolve (res.transform ([&modf](auto * d) { return modf (d->Write ()); }));
357
342
};
358
- op_manager_->Enqueue (KeyRef (dbid, key), value.GetExternalSlice (), std::move (cb));
343
+ op_manager_->Enqueue (KeyRef (dbid, key), value.GetExternalSlice (), tiering::StringDecoder{value},
344
+ std::move (cb));
359
345
return future;
360
346
}
361
347
0 commit comments