Skip to content

Commit

Permalink
Add 2 new TabletReader APIs: stripesMetadata and stripeGroupsMetadata (
Browse files Browse the repository at this point in the history
…#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.

Reviewed By: helfman

Differential Revision: D67957498
  • Loading branch information
Chongfeng Hu authored and facebook-github-bot committed Jan 10, 2025
1 parent 16e3878 commit e717f80
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
39 changes: 38 additions & 1 deletion 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 All @@ -48,7 +50,7 @@ namespace facebook::nimble {
// 4 bytes footer size + 1 byte footer compression type +
// 1 byte checksum type + 8 bytes checksum +
// 2 bytes major version + 2 bytes minor version +
// 4 bytes magic number.
// 2 bytes magic number.
namespace {

template <typename T>
Expand Down Expand Up @@ -648,6 +650,41 @@ uint64_t TabletReader::getTotalStreamSize(
return streamSizeSum;
}

std::optional<MetadataSection> TabletReader::stripesMetadata() const {
auto footerRoot =
asFlatBuffersRoot<serialization::Footer>(footer_->content());
auto stripes = footerRoot->stripes();
if (!stripes) {
return std::nullopt;
}
return MetadataSection{
stripes->offset(),
stripes->size(),
static_cast<CompressionType>(stripes->compression_type())};
}

std::vector<MetadataSection> TabletReader::stripeGroupsMetadata() const {
std::vector<MetadataSection> groupsMetadata;
auto footerRoot =
asFlatBuffersRoot<serialization::Footer>(footer_->content());
auto stripeGroups = footerRoot->stripe_groups();
if (!stripeGroups) {
return groupsMetadata;
}
groupsMetadata.reserve(stripeGroups->size());
std::transform(
stripeGroups->cbegin(),
stripeGroups->cend(),
std::back_inserter(groupsMetadata),
[](const auto& stripeGroup) {
return MetadataSection{
stripeGroup->offset(),
stripeGroup->size(),
static_cast<CompressionType>(stripeGroup->compression_type())};
});
return groupsMetadata;
}

std::optional<Section> TabletReader::loadOptionalSection(
const std::string& name,
bool keepCache) const {
Expand Down
8 changes: 8 additions & 0 deletions dwio/nimble/tablet/TabletReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
* limitations under the License.
*/
#pragma once

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

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

std::optional<MetadataSection> stripesMetadata() const;

std::vector<MetadataSection> stripeGroupsMetadata() const;

const std::unordered_map<std::string, MetadataSection>& optionalSections()
const {
return optionalSections_;
Expand Down

0 comments on commit e717f80

Please sign in to comment.