Skip to content

Commit 908462e

Browse files
Chongfeng Hufacebook-github-bot
Chongfeng Hu
authored andcommitted
Add 2 new TabletReader APIs: stripesMetadata and stripeGroupsMetadata (facebookincubator#126)
Summary: These 2 new APIs will allow clients to get insights into stripes and stripe groups metadata, e.g., offset, size, etc. This information can be useful in use cases like `nimble_dump` where we want to know the sizes of these sections in the Nimble file. Differential Revision: D67957498
1 parent c6fe269 commit 908462e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

dwio/nimble/tablet/TabletReader.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
#include "folly/io/Cursor.h"
2727

2828
#include <algorithm>
29+
#include <iterator>
2930
#include <limits>
31+
#include <memory>
3032
#include <numeric>
3133
#include <optional>
3234
#include <tuple>
@@ -325,6 +327,10 @@ TabletReader::TabletReader(
325327
NIMBLE_CHECK(
326328
stripes->offset() + readSize >= fileSize,
327329
"Incomplete stripes metadata.");
330+
stripesMetadata_ = std::make_unique<MetadataSection>(
331+
stripes->offset(),
332+
stripes->size(),
333+
static_cast<CompressionType>(stripes->compression_type()));
328334
stripes_ = std::make_unique<MetadataBuffer>(
329335
memoryPool_,
330336
footerIOBuf,
@@ -340,6 +346,16 @@ TabletReader::TabletReader(
340346
(stripeGroups->size() ==
341347
*stripesRoot->group_indices()->rbegin() + 1),
342348
"Unexpected stripe group count");
349+
std::transform(
350+
stripeGroups->cbegin(),
351+
stripeGroups->cend(),
352+
std::back_inserter(stripeGroupsMetadata_),
353+
[](const auto& stripeGroup) {
354+
return MetadataSection{
355+
stripeGroup->offset(),
356+
stripeGroup->size(),
357+
static_cast<CompressionType>(stripeGroup->compression_type())};
358+
});
343359

344360
// Always eagerly load if it's the only stripe group and is already
345361
// fetched

dwio/nimble/tablet/TabletReader.h

+13
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
* limitations under the License.
1515
*/
1616
#pragma once
17+
18+
#include <memory>
1719
#include <span>
20+
#include <vector>
1821

1922
#include "dwio/nimble/common/Checksum.h"
2023
#include "dwio/nimble/common/Types.h"
@@ -252,6 +255,14 @@ class TabletReader {
252255
const StripeIdentifier& stripe,
253256
std::span<const uint32_t> streamIdentifiers) const;
254257

258+
const MetadataSection* stripesMetadata() const {
259+
return stripesMetadata_.get();
260+
}
261+
262+
std::span<const MetadataSection> stripeGroupsMetadata() const {
263+
return stripeGroupsMetadata_;
264+
}
265+
255266
std::unordered_map<std::string, MetadataSection> optionalSections() const {
256267
return optionalSections_;
257268
}
@@ -354,6 +365,8 @@ class TabletReader {
354365
uint32_t stripeCount_{0};
355366
const uint32_t* stripeRowCounts_{nullptr};
356367
const uint64_t* stripeOffsets_{nullptr};
368+
std::unique_ptr<MetadataSection> stripesMetadata_;
369+
std::vector<MetadataSection> stripeGroupsMetadata_;
357370
std::unordered_map<std::string, MetadataSection> optionalSections_;
358371
mutable folly::Synchronized<
359372
std::unordered_map<std::string, std::unique_ptr<MetadataBuffer>>>

0 commit comments

Comments
 (0)