Skip to content

Commit

Permalink
issue-176: disable used block tracking (#2789)
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpeye authored Jan 7, 2025
1 parent c397ea2 commit a38b9ab
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 16 deletions.
42 changes: 26 additions & 16 deletions cloud/blockstore/libs/storage/volume/volume_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,34 @@ void TVolumeState::ResetThrottlingPolicy(
ThrottlerConfig.UseDiskSpaceScore));
}

bool TVolumeState::ShouldTrackUsedBlocks() const
{
if (!IsDiskRegistryMediaKind()) {
return false;
}

const bool overlay = !GetBaseDiskId().empty();
if (overlay) {
return true;
}

// TODO(drbasic)
// For encrypted disk-registry based disks, we will continue to
// write a map of encrypted blocks for a while.
const auto mode = Meta.GetVolumeConfig().GetEncryptionDesc().GetMode();

return mode != NProto::NO_ENCRYPTION &&
mode != NProto::ENCRYPTION_DEFAULT_AES_XTS;
}

void TVolumeState::Reset()
{
Partitions.clear();
PartitionStatInfos.clear();
PartitionsState = TPartitionInfo::UNKNOWN;
ForceRepair = false;
RejectWrite = false;
TrackUsedBlocks = false;
TrackUsedBlocks = ShouldTrackUsedBlocks();
MaskUnusedBlocks = false;
MaxTimedOutDeviceStateDuration = TDuration::Zero();
UseRdma = StorageConfig->GetUseRdma()
Expand All @@ -241,21 +261,11 @@ void TVolumeState::Reset()
AcceptInvalidDiskAllocationResponse = false;
UseIntermediateWriteBuffer = false;

if (IsDiskRegistryMediaKind()) {
if (Meta.GetDevices().size()) {
CreatePartitionStatInfo(GetDiskId(), 0);
}
const bool overlay = !GetBaseDiskId().empty();
// TODO(drbasic)
// For encrypted disk-registry based disks, we will continue to
// write a map of encrypted blocks for a while.
const bool encrypted =
Meta.GetVolumeConfig().GetEncryptionDesc().GetMode() !=
NProto::NO_ENCRYPTION;
if (encrypted || overlay) {
TrackUsedBlocks = true;
}
} else {
if (IsDiskRegistryMediaKind() && Meta.GetDevices().size()) {
CreatePartitionStatInfo(GetDiskId(), 0);
}

if (!IsDiskRegistryMediaKind()) {
for (ui64 tabletId: Meta.GetPartitions()) {
Partitions.emplace_back(
tabletId,
Expand Down
2 changes: 2 additions & 0 deletions cloud/blockstore/libs/storage/volume/volume_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,8 @@ class TVolumeState
bool ShouldForceTabletRestart(const NProto::TVolumeClientInfo& info) const;

THashSet<TString> MakeFilteredDeviceIds() const;

[[nodiscard]] bool ShouldTrackUsedBlocks() const;
};

} // namespace NCloud::NBlockStore::NStorage
64 changes: 64 additions & 0 deletions cloud/blockstore/libs/storage/volume/volume_state_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
#include <util/datetime/base.h>
#include <util/generic/guid.h>

#include <chrono>

namespace NCloud::NBlockStore::NStorage {

using namespace NActors;
using namespace std::chrono_literals;

namespace {

Expand Down Expand Up @@ -1869,6 +1872,67 @@ Y_UNIT_TEST_SUITE(TVolumeStateTest)
volumeState.GetMountHistory().GetItems()[i].Key);
}
}

Y_UNIT_TEST(ShouldNotTrackUsedBlocks)
{
auto makeState = [] (auto kind, auto mode) {
NProto::TVolumeMeta meta;

auto& config = *meta.MutableConfig();
config.SetStorageMediaKind(kind);

auto& volumeConfig = *meta.MutableVolumeConfig();
auto& part = *volumeConfig.AddPartitions();
part.SetBlockCount(1);

auto& desc = *volumeConfig.MutableEncryptionDesc();
desc.SetMode(mode);

return TVolumeState{
MakeConfig(10s, 0s),
std::move(meta),
{}, // metaHistory
{}, // volumeParams
CreateThrottlerConfig(),
{}, // infos
{}, // mountHistory
{}, // checkpointRequests
false // startPartitionsNeeded
};
};

{
auto state = makeState(
NProto::STORAGE_MEDIA_SSD_NONREPLICATED,
NProto::ENCRYPTION_DEFAULT_AES_XTS);

UNIT_ASSERT(!state.GetTrackUsedBlocks());
}

{
auto state = makeState(
NProto::STORAGE_MEDIA_SSD_NONREPLICATED,
NProto::NO_ENCRYPTION);

UNIT_ASSERT(!state.GetTrackUsedBlocks());
}

{
auto state = makeState(
NProto::STORAGE_MEDIA_SSD_NONREPLICATED,
NProto::ENCRYPTION_AES_XTS);

UNIT_ASSERT(state.GetTrackUsedBlocks());
}

{
auto state = makeState(
NProto::STORAGE_MEDIA_SSD,
NProto::ENCRYPTION_AES_XTS);

UNIT_ASSERT(!state.GetTrackUsedBlocks());
}
}
}

} // namespace NCloud::NBlockStore::NStorage
Expand Down
16 changes: 16 additions & 0 deletions cloud/blockstore/tests/encryption_at_rest/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,19 @@ def read_first_block():
assert raw_data != expected_data

session.unmount_volume()

# check that the volume doesn't tack used blocks

response = json.loads(client.execute_action(
action="UpdateUsedBlocks",
input_bytes=json.dumps({
"DiskId": "vol0",
"StartIndices": [0],
"BlockCounts": [1],
"Used": True
}).encode()))

error = response.get("Error", {})

assert error.get("Code") == 1 # S_FALSE
assert error.get("Message") == "Used block tracking not set up"

0 comments on commit a38b9ab

Please sign in to comment.