Skip to content

Commit

Permalink
use max pk in portion as eviction border (#13806)
Browse files Browse the repository at this point in the history
  • Loading branch information
swalrus1 committed Jan 26, 2025
1 parent 556de27 commit e99c6d9
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 13 deletions.
6 changes: 3 additions & 3 deletions ydb/core/kqp/ut/olap/helpers/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

namespace NKikimr::NKqp {

void WriteTestData(TKikimrRunner& kikimr, TString testTable, ui64 pathIdBegin, ui64 tsBegin, size_t rowCount, bool withSomeNulls /*= false*/) {
void WriteTestData(TKikimrRunner& kikimr, TString testTable, ui64 pathIdBegin, ui64 tsBegin, size_t rowCount, bool withSomeNulls /*= false*/,
ui64 tsStepUs /*= 1*/) {
UNIT_ASSERT(testTable != "/Root/benchTable"); // TODO: check schema instead
TLocalHelper lHelper(kikimr);
if (withSomeNulls) {
lHelper.WithSomeNulls();
}
auto batch = lHelper.TestArrowBatch(pathIdBegin, tsBegin, rowCount);
auto batch = lHelper.TestArrowBatch(pathIdBegin, tsBegin, rowCount, tsStepUs);
lHelper.SendDataViaActorSystem(testTable, batch);
}

}
4 changes: 2 additions & 2 deletions ydb/core/kqp/ut/olap/helpers/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

namespace NKikimr::NKqp {

void WriteTestData(TKikimrRunner& kikimr, TString testTable, ui64 pathIdBegin, ui64 tsBegin, size_t rowCount, bool withSomeNulls = false);

void WriteTestData(
TKikimrRunner& kikimr, TString testTable, ui64 pathIdBegin, ui64 tsBegin, size_t rowCount, bool withSomeNulls = false, ui64 tsStepUs = 1);
}
61 changes: 61 additions & 0 deletions ydb/core/kqp/ut/olap/tiering_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,67 @@ Y_UNIT_TEST_SUITE(KqpOlapTiering) {
UNIT_ASSERT_VALUES_EQUAL(GetInt32(rows[0].at("level")), maxLevelValue);
}
}

Y_UNIT_TEST(TtlBorders) {
auto csController = NYDBTest::TControllers::RegisterCSControllerGuard<NOlap::TWaitCompactionController>();

TKikimrSettings runnerSettings;
runnerSettings.WithSampleTables = false;
TTestHelper testHelper(runnerSettings);
TLocalHelper localHelper(testHelper.GetKikimr());
testHelper.GetRuntime().SetLogPriority(NKikimrServices::TX_TIERING, NActors::NLog::PRI_DEBUG);
NYdb::NTable::TTableClient tableClient = testHelper.GetKikimr().GetTableClient();
Tests::NCommon::TLoggerInit(testHelper.GetKikimr()).Initialize();
Singleton<NKikimr::NWrappers::NExternalStorage::TFakeExternalStorage>()->SetSecretKey("fakeSecret");

localHelper.CreateTestOlapTable("olapTable", "olapStore", 1, 1);

{
const TDuration tsInterval = TDuration::Days(3650);
const ui64 rows = 10000;
WriteTestData(testHelper.GetKikimr(), "/Root/olapStore/olapTable", 0, (TInstant::Now() - tsInterval).MicroSeconds(), rows,
false, tsInterval.MicroSeconds() / rows);
}

{
auto selectQuery = TString(R"(
SELECT MAX(timestamp) AS timestamp FROM `/Root/olapStore/olapTable`
)");

auto rows = ExecuteScanQuery(tableClient, selectQuery);
UNIT_ASSERT_VALUES_EQUAL(rows.size(), 1);
UNIT_ASSERT_GT(GetTimestamp(rows[0].at("timestamp")), TInstant::Now() - TDuration::Days(100));
}

{
auto selectQuery = TString(R"(
SELECT COUNT(*) AS count FROM `/Root/olapStore/olapTable/.sys/primary_index_portion_stats`
)");

auto rows = ExecuteScanQuery(tableClient, selectQuery);
UNIT_ASSERT_VALUES_EQUAL(rows.size(), 1);
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[0].at("count")), 1);
}

{
const TString query = R"(ALTER TABLE `/Root/olapStore/olapTable` SET TTL Interval("P300D") ON timestamp)";
auto result = testHelper.GetSession().ExecuteSchemeQuery(query).GetValueSync();
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), NYdb::EStatus::SUCCESS, result.GetIssues().ToString());
}

csController->WaitCompactions(TDuration::Seconds(5));
csController->WaitActualization(TDuration::Seconds(5));

{
auto selectQuery = TString(R"(
SELECT COUNT(*) AS count FROM `/Root/olapStore/olapTable`
)");

auto rows = ExecuteScanQuery(tableClient, selectQuery);
UNIT_ASSERT_VALUES_EQUAL(rows.size(), 1);
UNIT_ASSERT_GT(GetUint64(rows[0].at("count")), 0);
}
}
}

} // namespace NKikimr::NKqp
6 changes: 3 additions & 3 deletions ydb/core/testlib/cs_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ std::shared_ptr<arrow::Schema> THelper::GetArrowSchema() const {
return std::make_shared<arrow::Schema>(std::move(fields));
}

std::shared_ptr<arrow::RecordBatch> THelper::TestArrowBatch(ui64 pathIdBegin, ui64 tsBegin, size_t rowCount, const ui32 tsStepUs) const {
std::shared_ptr<arrow::RecordBatch> THelper::TestArrowBatch(ui64 pathIdBegin, ui64 tsBegin, size_t rowCount, const ui64 tsStepUs) const {
std::shared_ptr<arrow::Schema> schema = GetArrowSchema();

arrow::TimestampBuilder b1(arrow::timestamp(arrow::TimeUnit::TimeUnit::MICRO), arrow::default_memory_pool());
Expand Down Expand Up @@ -368,7 +368,7 @@ std::shared_ptr<arrow::Schema> TCickBenchHelper::GetArrowSchema() const {
});
}

std::shared_ptr<arrow::RecordBatch> TCickBenchHelper::TestArrowBatch(ui64, ui64 begin, size_t rowCount, const ui32 tsStepUs) const {
std::shared_ptr<arrow::RecordBatch> TCickBenchHelper::TestArrowBatch(ui64, ui64 begin, size_t rowCount, const ui64 tsStepUs) const {
std::shared_ptr<arrow::Schema> schema = GetArrowSchema();
UNIT_ASSERT(schema);
UNIT_ASSERT(schema->num_fields());
Expand Down Expand Up @@ -441,7 +441,7 @@ std::shared_ptr<arrow::RecordBatch> TTableWithNullsHelper::TestArrowBatch() cons
return TestArrowBatch(0, 0, 10, 1);
}

std::shared_ptr<arrow::RecordBatch> TTableWithNullsHelper::TestArrowBatch(ui64, ui64, size_t rowCount, const ui32 /*tsStepUs*/) const {
std::shared_ptr<arrow::RecordBatch> TTableWithNullsHelper::TestArrowBatch(ui64, ui64, size_t rowCount, const ui64 /*tsStepUs*/) const {
rowCount = 10;
std::shared_ptr<arrow::Schema> schema = GetArrowSchema();

Expand Down
8 changes: 4 additions & 4 deletions ydb/core/testlib/cs_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class THelperSchemaless : public NCommon::THelper {
void SendDataViaActorSystem(TString testTable, ui64 pathIdBegin, ui64 tsBegin, size_t rowCount, const ui32 tsStepUs = 1) const;
void SendDataViaActorSystem(TString testTable, std::shared_ptr<arrow::RecordBatch> batch, const Ydb::StatusIds_StatusCode& expectedStatus = Ydb::StatusIds::SUCCESS) const;

virtual std::shared_ptr<arrow::RecordBatch> TestArrowBatch(ui64 pathIdBegin, ui64 tsBegin, size_t rowCount, const ui32 tsStepUs = 1) const = 0;
virtual std::shared_ptr<arrow::RecordBatch> TestArrowBatch(ui64 pathIdBegin, ui64 tsBegin, size_t rowCount, const ui64 tsStepUs = 1) const = 0;
};

class THelper: public THelperSchemaless {
Expand Down Expand Up @@ -68,7 +68,7 @@ class THelper: public THelperSchemaless {
}
virtual TString GetTestTableSchema() const;

virtual std::shared_ptr<arrow::RecordBatch> TestArrowBatch(ui64 pathIdBegin, ui64 tsBegin, size_t rowCount, const ui32 tsStepUs = 1) const override;
virtual std::shared_ptr<arrow::RecordBatch> TestArrowBatch(ui64 pathIdBegin, ui64 tsBegin, size_t rowCount, const ui64 tsStepUs = 1) const override;
};

class TCickBenchHelper: public THelperSchemaless {
Expand Down Expand Up @@ -189,7 +189,7 @@ class TCickBenchHelper: public THelperSchemaless {
KeyColumnNames: ["EventTime", "EventDate", "CounterID", "UserID", "WatchID"]
)";

std::shared_ptr<arrow::RecordBatch> TestArrowBatch(ui64, ui64 begin, size_t rowCount, const ui32 tsStepUs = 1) const override;
std::shared_ptr<arrow::RecordBatch> TestArrowBatch(ui64, ui64 begin, size_t rowCount, const ui64 tsStepUs = 1) const override;
};

class TTableWithNullsHelper: public THelperSchemaless {
Expand All @@ -210,7 +210,7 @@ class TTableWithNullsHelper: public THelperSchemaless {
KeyColumnNames: "id"
)";

std::shared_ptr<arrow::RecordBatch> TestArrowBatch(ui64, ui64, size_t rowCount = 10, const ui32 tsStepUs = 1) const override;
std::shared_ptr<arrow::RecordBatch> TestArrowBatch(ui64, ui64, size_t rowCount = 10, const ui64 tsStepUs = 1) const override;
std::shared_ptr<arrow::RecordBatch> TestArrowBatch() const;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ void TTieringActualizer::DoAddPortion(const TPortionInfo& portion, const TAddExt
auto schema = portion.GetSchema(VersionedIndex);
if (*TValidator::CheckNotNull(TieringColumnId) == schema->GetIndexInfo().GetPKColumnIds().front()) {
NYDBTest::TControllers::GetColumnShardController()->OnMaxValueUsage();
auto max = NArrow::TStatusValidator::GetValid(portion.GetMeta().GetFirstLastPK().GetFirst().Column(0).GetScalar(0));
const auto lastPk = portion.GetMeta().GetFirstLastPK().GetLast();
const auto max = NArrow::TStatusValidator::GetValid(lastPk.Column(0).GetScalar(lastPk.GetPosition()));
AFL_VERIFY(MaxByPortionId.emplace(portion.GetPortionId(), max).second);
AddPortionImpl(portion, addContext.GetNow());
} else {
Expand Down

0 comments on commit e99c6d9

Please sign in to comment.