Skip to content

Commit

Permalink
Add 2 new TabletReader APIs: stripesMetadata and stripeGroupsMetadata (
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Chongfeng Hu authored and facebook-github-bot committed Jan 9, 2025
1 parent c6fe269 commit 908462e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions dwio/nimble/tablet/TabletReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
#include "folly/io/Cursor.h"

#include <algorithm>
#include <iterator>
#include <limits>
#include <memory>
#include <numeric>
#include <optional>
#include <tuple>
Expand Down Expand Up @@ -325,6 +327,10 @@ TabletReader::TabletReader(
NIMBLE_CHECK(
stripes->offset() + readSize >= fileSize,
"Incomplete stripes metadata.");
stripesMetadata_ = std::make_unique<MetadataSection>(
stripes->offset(),
stripes->size(),
static_cast<CompressionType>(stripes->compression_type()));
stripes_ = std::make_unique<MetadataBuffer>(
memoryPool_,
footerIOBuf,
Expand All @@ -340,6 +346,16 @@ TabletReader::TabletReader(
(stripeGroups->size() ==
*stripesRoot->group_indices()->rbegin() + 1),
"Unexpected stripe group count");
std::transform(
stripeGroups->cbegin(),
stripeGroups->cend(),
std::back_inserter(stripeGroupsMetadata_),
[](const auto& stripeGroup) {
return MetadataSection{
stripeGroup->offset(),
stripeGroup->size(),
static_cast<CompressionType>(stripeGroup->compression_type())};
});

// Always eagerly load if it's the only stripe group and is already
// fetched
Expand Down
13 changes: 13 additions & 0 deletions dwio/nimble/tablet/TabletReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* limitations under the License.
*/
#pragma once

#include <memory>
#include <span>
#include <vector>

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

const MetadataSection* stripesMetadata() const {
return stripesMetadata_.get();
}

std::span<const MetadataSection> stripeGroupsMetadata() const {
return stripeGroupsMetadata_;
}

std::unordered_map<std::string, MetadataSection> optionalSections() const {
return optionalSections_;
}
Expand Down Expand Up @@ -354,6 +365,8 @@ class TabletReader {
uint32_t stripeCount_{0};
const uint32_t* stripeRowCounts_{nullptr};
const uint64_t* stripeOffsets_{nullptr};
std::unique_ptr<MetadataSection> stripesMetadata_;
std::vector<MetadataSection> stripeGroupsMetadata_;
std::unordered_map<std::string, MetadataSection> optionalSections_;
mutable folly::Synchronized<
std::unordered_map<std::string, std::unique_ptr<MetadataBuffer>>>
Expand Down

0 comments on commit 908462e

Please sign in to comment.