Skip to content

Commit a89aa3a

Browse files
daverigbytrondn
authored andcommitted
CBD-6348: [BP] Remove deprecated format_to(memory_buffer) overload
This is a cherry-pick from trinity fmtlib 8.0 has deprecated the overload of format_to() taking a memory_buffer - see fmtlib/fmt@e77b22d Replace by calling the format_to overload taking an Output Iterator, by explicitly wrapping the memory_buffer in std::back_inserter. Change-Id: I43660ef8159e6cc94558df494d6ba2f0b82a53bc Reviewed-on: https://review.couchbase.org/c/kv_engine/+/234745 Reviewed-by: Jim Walker <[email protected]> Well-Formed: Restriction Checker Tested-by: Trond Norbye <[email protected]>
1 parent f6faa7e commit a89aa3a

File tree

10 files changed

+88
-59
lines changed

10 files changed

+88
-59
lines changed

engines/ep/benchmarks/hash_table_bench.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class HashTableBench : public benchmark::Fixture {
4949
// Use fmtlib to format key with stack-local (non-heap) buffer to
5050
// minimise the cost of constructing keys for Items.
5151
fmt::memory_buffer keyBuf;
52-
format_to(keyBuf, "{}{}", keyPrefix, i);
52+
fmt::format_to(std::back_inserter(keyBuf), "{}{}", keyPrefix, i);
5353
// Note: fmt::memory_buffer is not null-terminated, cannot use the
5454
// cstring-ctor
5555
return StoredDocKey(to_string(keyBuf), collection);

engines/ep/src/bucket_logger.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,21 @@ void BucketLogger::logInner(spdlog::level::level_enum lvl,
6363

6464
// Append the id (if set)
6565
if (connectionId != 0) {
66-
fmt::format_to(msg, "{}: ", connectionId);
66+
fmt::format_to(std::back_inserter(msg), "{}: ", connectionId);
6767
}
6868

6969
// Append the engine name (if applicable)
70-
fmt::format_to(msg, "({}) ", engine ? engine->getName() : "No Engine");
70+
fmt::format_to(std::back_inserter(msg),
71+
"({}) ",
72+
engine ? engine->getName() : "No Engine");
7173

7274
// Append the given prefix (if set)
7375
if (!prefix.empty()) {
74-
fmt::format_to(msg, "{} ", prefix);
76+
fmt::format_to(std::back_inserter(msg), "{} ", prefix);
7577
}
7678

7779
// Finally format the actual user-specified format string & args.
78-
fmt::vformat_to(msg, fmt, args);
80+
fmt::vformat_to(std::back_inserter(msg), fmt, args);
7981
spdlog::logger::log(lvl, {msg.data(), msg.size()});
8082
} catch (std::exception& e) {
8183
// Log a fixed message about this failing - we can't really be sure

engines/ep/src/collections/vbucket_manifest.cc

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,19 +1461,22 @@ bool Manifest::addCollectionStats(Vbid vbid,
14611461
const StatCollector& collector) const {
14621462
fmt::memory_buffer key;
14631463

1464-
format_to(key, "vb_{}:collections", vbid.get());
1464+
fmt::format_to(std::back_inserter(key), "vb_{}:collections", vbid.get());
14651465
collector.addStat(std::string_view(key.data(), key.size()), map.size());
14661466

14671467
key.resize(0);
14681468

1469-
format_to(key, "vb_{}:manifest:uid", vbid.get());
1469+
fmt::format_to(std::back_inserter(key), "vb_{}:manifest:uid", vbid.get());
14701470
collector.addStat(std::string_view(key.data(), key.size()), manifestUid);
14711471

14721472
if (doesDefaultCollectionExist()) {
1473-
format_to(key, "vb_{}:default_mvs", vbid.get());
1473+
fmt::format_to(
1474+
std::back_inserter(key), "vb_{}:default_mvs", vbid.get());
14741475
collector.addStat(std::string_view(key.data(), key.size()),
14751476
defaultCollectionMaxVisibleSeqno);
1476-
format_to(key, "vb_{}:default_legacy_max_dcp_seqno", vbid.get());
1477+
fmt::format_to(std::back_inserter(key),
1478+
"vb_{}:default_legacy_max_dcp_seqno",
1479+
vbid.get());
14771480
collector.addStat(std::string_view(key.data(), key.size()),
14781481
defaultCollectionMaxLegacyDCPSeqno);
14791482
}
@@ -1490,31 +1493,37 @@ bool Manifest::addCollectionStats(Vbid vbid,
14901493
bool Manifest::addScopeStats(Vbid vbid, const StatCollector& collector) const {
14911494
fmt::memory_buffer key;
14921495

1493-
format_to(key, "vb_{}:scopes", vbid.get());
1496+
fmt::format_to(std::back_inserter(key), "vb_{}:scopes", vbid.get());
14941497
collector.addStat(std::string_view(key.data(), key.size()), scopes.size());
14951498

14961499
key.resize(0);
14971500

1498-
format_to(key, "vb_{}:manifest:uid", vbid.get());
1501+
fmt::format_to(std::back_inserter(key), "vb_{}:manifest:uid", vbid.get());
14991502
collector.addStat(std::string_view(key.data(), key.size()), manifestUid);
15001503

1501-
format_to(key, "vb_{}:scope_data_limit", vbid.get());
1504+
fmt::format_to(
1505+
std::back_inserter(key), "vb_{}:scope_data_limit", vbid.get());
15021506
collector.addStat(std::string_view(key.data(), key.size()),
15031507
scopeWithDataLimitExists);
15041508

15051509
for (const auto& [sid, value] : scopes) {
15061510
key.resize(0);
1507-
format_to(key, "vb_{}:{}:name:", vbid.get(), sid);
1511+
fmt::format_to(
1512+
std::back_inserter(key), "vb_{}:{}:name:", vbid.get(), sid);
15081513
collector.addStat(std::string_view(key.data(), key.size()),
15091514
value.getName());
15101515
key.resize(0);
1511-
format_to(key, "vb_{}:{}:data_size", vbid.get(), sid);
1516+
fmt::format_to(
1517+
std::back_inserter(key), "vb_{}:{}:data_size", vbid.get(), sid);
15121518
collector.addStat(std::string_view(key.data(), key.size()),
15131519
value.getDataSize());
15141520

15151521
if (value.getDataLimit()) {
15161522
key.resize(0);
1517-
format_to(key, "vb_{}:{}:data_limit", vbid.get(), sid);
1523+
fmt::format_to(std::back_inserter(key),
1524+
"vb_{}:{}:data_limit",
1525+
vbid.get(),
1526+
sid);
15181527
collector.addStat(std::string_view(key.data(), key.size()),
15191528
value.getDataLimit().value());
15201529
}
@@ -1526,8 +1535,11 @@ bool Manifest::addScopeStats(Vbid vbid, const StatCollector& collector) const {
15261535
for (const auto& [cid, entry] : map) {
15271536
key.resize(0);
15281537

1529-
format_to(
1530-
key, "vb_{}:{}:{}:items", vbid.get(), entry.getScopeID(), cid);
1538+
fmt::format_to(std::back_inserter(key),
1539+
"vb_{}:{}:{}:items",
1540+
vbid.get(),
1541+
entry.getScopeID(),
1542+
cid);
15311543
collector.addStat(std::string_view(key.data(), key.size()),
15321544
entry.getItemCount());
15331545
}
@@ -1815,14 +1827,14 @@ bool Manifest::DroppedCollections::addStats(
18151827
bool Manifest::DroppedCollectionInfo::addStats(
18161828
Vbid vbid, CollectionID cid, const StatCollector& collector) const {
18171829
fmt::memory_buffer prefix;
1818-
format_to(prefix, "vb_{}:{}", vbid.get(), cid);
1830+
fmt::format_to(std::back_inserter(prefix), "vb_{}:{}", vbid.get(), cid);
18191831
const auto addStat = [&prefix, &collector](const auto& statKey,
18201832
auto statValue) {
18211833
fmt::memory_buffer key;
1822-
format_to(key,
1823-
"{}:{}",
1824-
std::string_view{prefix.data(), prefix.size()},
1825-
statKey);
1834+
fmt::format_to(std::back_inserter(key),
1835+
"{}:{}",
1836+
std::string_view{prefix.data(), prefix.size()},
1837+
statKey);
18261838
collector.addStat(std::string_view(key.data(), key.size()), statValue);
18271839
};
18281840

engines/ep/src/collections/vbucket_manifest_entry.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ bool Collections::VB::ManifestEntry::addStats(
4040
Vbid vbid,
4141
const StatCollector& collector) const {
4242
fmt::memory_buffer key;
43-
format_to(key, "vb_{}:{}:", vbid.get(), cid);
43+
fmt::format_to(std::back_inserter(key), "vb_{}:{}:", vbid.get(), cid);
4444
const auto prefixLen = key.size();
4545

4646
const auto addStat = [&key, prefixLen, &collector](std::string_view statKey,

engines/ep/src/connhandler.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,15 +402,15 @@ std::string ConnHandler::getPausedDetails() const {
402402
const auto count = details.reasonCounts[reason];
403403
if (count) {
404404
if (addComma) {
405-
format_to(buf, ",");
405+
fmt::format_to(std::back_inserter(buf), ",");
406406
}
407407
addComma = true;
408408
const auto duration = details.reasonDurations[reason];
409-
format_to(buf,
410-
R"("{}": {{"count":{}, "duration":"{}"}})",
411-
to_string(ConnHandler::PausedReason{reason}),
412-
count,
413-
cb::time2text(duration));
409+
fmt::format_to(std::back_inserter(buf),
410+
R"("{}": {{"count":{}, "duration":"{}"}})",
411+
to_string(ConnHandler::PausedReason{reason}),
412+
count,
413+
cb::time2text(duration));
414414
totalCount += count;
415415
totalDuration += duration;
416416
}

engines/ep/src/dcp/active_stream.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,12 +829,13 @@ void ActiveStream::addStats(const AddStatFn& add_stat, const CookieIface* c) {
829829

830830
try {
831831
fmt::memory_buffer keyBuff;
832-
fmt::format_to(keyBuff, "{}:stream_{}_", name_, vb_.get());
832+
fmt::format_to(
833+
std::back_inserter(keyBuff), "{}:stream_{}_", name_, vb_.get());
833834
const auto prefixLen = keyBuff.size();
834835
const auto addStat = [&keyBuff, prefixLen, add_stat, c](
835836
const auto& statKey, auto statValue) {
836837
keyBuff.resize(prefixLen);
837-
fmt::format_to(keyBuff, "{}", statKey);
838+
fmt::format_to(std::back_inserter(keyBuff), "{}", statKey);
838839
add_casted_stat(
839840
{keyBuff.data(), keyBuff.size()}, statValue, add_stat, c);
840841
};

engines/ep/src/kvstore/magma-kvstore/magma-kvstore.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ MetaData makeMetaData(const Item& it) {
9494
std::string MetaData::to_string() const {
9595
fmt::memory_buffer memoryBuffer;
9696
fmt::format_to(
97-
memoryBuffer,
97+
std::back_inserter(memoryBuffer),
9898
"bySeqno:{} cas:{} exptime:{} revSeqno:{} flags:{} valueSize:{} "
9999
"deleted:{} deleteSource:{} version:{} datatype:{}",
100100
allMeta.v0.bySeqno,
@@ -113,12 +113,12 @@ std::string MetaData::to_string() const {
113113
if (getVersion() == Version::V1) {
114114
if (allMeta.v0.bits.deleted) {
115115
// abort
116-
fmt::format_to(memoryBuffer,
116+
fmt::format_to(std::back_inserter(memoryBuffer),
117117
" prepareSeqno:{}",
118118
allMeta.v1.durabilityDetails.completed.prepareSeqno);
119119
} else {
120120
// prepare
121-
fmt::format_to(memoryBuffer,
121+
fmt::format_to(std::back_inserter(memoryBuffer),
122122
" durabilityLevel:{} syncDelete:{}",
123123
allMeta.v1.durabilityDetails.pending.level,
124124
allMeta.v1.durabilityDetails.pending.isDelete);

engines/ep/tests/module_tests/collections/collections_oso_dcp_test.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,9 +633,7 @@ void CollectionsOSODcpTest::MB_43700(CollectionID cid) {
633633
resetEngineAndWarmup();
634634

635635
nlohmann::json filter;
636-
fmt::memory_buffer key;
637-
format_to(key, "{:x}", uint32_t(cid));
638-
filter["collections"] = {std::string_view{key.data(), key.size()}};
636+
filter["collections"] = {fmt::format("{:x}", uint32_t(cid))};
639637
createDcpObjects(filter.dump(), OutOfOrderSnapshots::Yes);
640638

641639
// We have a single filter, expect the backfill to be OSO

include/statistics/cbstat_collector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,6 @@ void add_prefixed_stat(P prefix,
135135
const AddStatFn& add_stat,
136136
const void* cookie) {
137137
fmt::memory_buffer buf;
138-
format_to(buf, "{}:{}", prefix, name);
138+
fmt::format_to(std::back_inserter(buf), "{}:{}", prefix, name);
139139
add_casted_stat({buf.data(), buf.size()}, val, add_stat, cookie);
140140
}

statistics/cbstat_collector.cc

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,31 +54,31 @@ void CBStatCollector::addStat(const cb::stats::StatDef& k,
5454
int64_t v,
5555
const Labels& labels) const {
5656
fmt::memory_buffer buf;
57-
format_to(buf, "{}", v);
57+
fmt::format_to(std::back_inserter(buf), "{}", v);
5858
addStat(k, {buf.data(), buf.size()}, labels);
5959
}
6060

6161
void CBStatCollector::addStat(const cb::stats::StatDef& k,
6262
uint64_t v,
6363
const Labels& labels) const {
6464
fmt::memory_buffer buf;
65-
format_to(buf, "{}", v);
65+
fmt::format_to(std::back_inserter(buf), "{}", v);
6666
addStat(k, {buf.data(), buf.size()}, labels);
6767
}
6868

6969
void CBStatCollector::addStat(const cb::stats::StatDef& k,
7070
float v,
7171
const Labels& labels) const {
7272
fmt::memory_buffer buf;
73-
format_to(buf, "{}", v);
73+
fmt::format_to(std::back_inserter(buf), "{}", v);
7474
addStat(k, {buf.data(), buf.size()}, labels);
7575
}
7676

7777
void CBStatCollector::addStat(const cb::stats::StatDef& k,
7878
double v,
7979
const Labels& labels) const {
8080
fmt::memory_buffer buf;
81-
format_to(buf, "{}", v);
81+
fmt::format_to(std::back_inserter(buf), "{}", v);
8282
addStat(k, {buf.data(), buf.size()}, labels);
8383
}
8484

@@ -88,13 +88,17 @@ void CBStatCollector::addStat(const cb::stats::StatDef& k,
8888
auto key = k.needsFormatting() ? formatKey(k.cbstatsKey, labels)
8989
: std::string(k.cbstatsKey);
9090
fmt::memory_buffer buf;
91-
format_to(buf, "{}_mean", key);
91+
fmt::format_to(std::back_inserter(buf), "{}_mean", key);
9292
addStat(cb::stats::StatDef({buf.data(), buf.size()}), hist.mean, labels);
9393

9494
uint64_t cumulativeCount = 0;
9595
for (const auto& bucket : hist.buckets) {
9696
buf.resize(0);
97-
format_to(buf, "{}_{},{}", key, bucket.lowerBound, bucket.upperBound);
97+
fmt::format_to(std::back_inserter(buf),
98+
"{}_{},{}",
99+
key,
100+
bucket.lowerBound,
101+
bucket.upperBound);
98102
addStat(cb::stats::StatDef({buf.data(), buf.size()}),
99103
bucket.count,
100104
labels);
@@ -108,12 +112,12 @@ void CBStatCollector::addStat(const cb::stats::StatDef& k,
108112
const auto overflowed = hist.sampleCount - cumulativeCount;
109113
if (overflowed) {
110114
buf.resize(0);
111-
format_to(buf, "{}_overflowed", key);
115+
fmt::format_to(std::back_inserter(buf), "{}_overflowed", key);
112116
addStat(cb::stats::StatDef({buf.data(), buf.size()}),
113117
overflowed,
114118
labels);
115119
buf.resize(0);
116-
format_to(buf, "{}_maxTrackable", key);
120+
fmt::format_to(std::back_inserter(buf), "{}_maxTrackable", key);
117121
addStat(cb::stats::StatDef({buf.data(), buf.size()}),
118122
hist.maxTrackableValue,
119123
labels);
@@ -209,26 +213,35 @@ auto formatFromMap(fmt::memory_buffer& buf,
209213

210214
switch (labels.size()) {
211215
case 0:
212-
return fmt::format_to(buf, formatStr);
216+
return fmt::format_to(std::back_inserter(buf), formatStr);
213217
case 1:
214-
return fmt::format_to(buf, formatStr, getArg());
218+
return fmt::format_to(std::back_inserter(buf), formatStr, getArg());
215219
case 2:
216-
return fmt::format_to(buf, formatStr, getArg(), getArg());
220+
return fmt::format_to(
221+
std::back_inserter(buf), formatStr, getArg(), getArg());
217222
case 3:
218-
return fmt::format_to(buf, formatStr, getArg(), getArg(), getArg());
223+
return fmt::format_to(std::back_inserter(buf),
224+
formatStr,
225+
getArg(),
226+
getArg(),
227+
getArg());
219228
case 4:
220-
return fmt::format_to(
221-
buf, formatStr, getArg(), getArg(), getArg(), getArg());
229+
return fmt::format_to(std::back_inserter(buf),
230+
formatStr,
231+
getArg(),
232+
getArg(),
233+
getArg(),
234+
getArg());
222235
case 5:
223-
return fmt::format_to(buf,
236+
return fmt::format_to(std::back_inserter(buf),
224237
formatStr,
225238
getArg(),
226239
getArg(),
227240
getArg(),
228241
getArg(),
229242
getArg());
230243
case 6:
231-
return fmt::format_to(buf,
244+
return fmt::format_to(std::back_inserter(buf),
232245
formatStr,
233246
getArg(),
234247
getArg(),
@@ -237,7 +250,7 @@ auto formatFromMap(fmt::memory_buffer& buf,
237250
getArg(),
238251
getArg());
239252
case 7:
240-
return fmt::format_to(buf,
253+
return fmt::format_to(std::back_inserter(buf),
241254
formatStr,
242255
getArg(),
243256
getArg(),
@@ -247,7 +260,7 @@ auto formatFromMap(fmt::memory_buffer& buf,
247260
getArg(),
248261
getArg());
249262
case 8:
250-
return fmt::format_to(buf,
263+
return fmt::format_to(std::back_inserter(buf),
251264
formatStr,
252265
getArg(),
253266
getArg(),
@@ -270,16 +283,19 @@ std::string CBStatCollector::formatKey(std::string_view key,
270283
// if this stat was added through a scope or collection collector,
271284
// prepend the appropriate prefix
272285
if (labels.count("scope_id")) {
273-
fmt::format_to(buf, "{}:", labels.at("scope_id"));
286+
fmt::format_to(
287+
std::back_inserter(buf), "{}:", labels.at("scope_id"));
274288
if (labels.count("collection_id")) {
275-
fmt::format_to(buf, "{}:", labels.at("collection_id"));
289+
fmt::format_to(std::back_inserter(buf),
290+
"{}:",
291+
labels.at("collection_id"));
276292
}
277293
}
278294
// now format the key itself, it may contain replacement specifiers
279295
// that can only be replaced with the appropriate value at runtime
280296
formatFromMap(buf, key, labels);
281297

282-
return {buf.data(), buf.size()};
298+
return fmt::to_string(buf);
283299

284300
} catch (const fmt::format_error& e) {
285301
throw std::runtime_error(

0 commit comments

Comments
 (0)