Skip to content

Commit

Permalink
Ydb stable 22-4-31
Browse files Browse the repository at this point in the history
x-stable-origin-commit: 2bc59c7eeae4a8f3d396867de193d1375dd388ce
  • Loading branch information
dcherednik committed Oct 22, 2022
1 parent 0b931ad commit 11bc401
Show file tree
Hide file tree
Showing 35 changed files with 876 additions and 150 deletions.
190 changes: 111 additions & 79 deletions ydb/core/blobstorage/dsproxy/dsproxy_patch.cpp

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion ydb/core/blobstorage/nodewarden/node_warden_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,14 @@ void TNodeWarden::Handle(TEvStatusUpdate::TPtr ev) {
auto *msg = ev->Get();
const TVSlotId vslotId(msg->NodeId, msg->PDiskId, msg->VSlotId);
if (const auto it = LocalVDisks.find(vslotId); it != LocalVDisks.end() && it->second.Status != msg->Status) {
it->second.Status = msg->Status;
auto& vdisk = it->second;
vdisk.Status = msg->Status;
SendDiskMetrics(false);

if (msg->Status == NKikimrBlobStorage::EVDiskStatus::READY && vdisk.WhiteboardVDiskId) {
Send(WhiteboardId, new NNodeWhiteboard::TEvWhiteboard::TEvVDiskDropDonors(*vdisk.WhiteboardVDiskId,
vdisk.WhiteboardInstanceGuid, NNodeWhiteboard::TEvWhiteboard::TEvVDiskDropDonors::TDropAllDonors()));
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions ydb/core/blobstorage/nodewarden/node_warden_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ namespace NKikimr::NStorage {
return MakeBlobStorageVDiskID(NodeId, PDiskId, VDiskSlotId);
}

void Serialize(NKikimrBlobStorage::TVSlotId *proto) const {
proto->SetNodeId(NodeId);
proto->SetPDiskId(PDiskId);
proto->SetVSlotId(VDiskSlotId);
}

auto AsTuple() const { return std::make_tuple(NodeId, PDiskId, VDiskSlotId); }
friend bool operator <(const TVSlotId& x, const TVSlotId& y) { return x.AsTuple() < y.AsTuple(); }
friend bool operator <=(const TVSlotId& x, const TVSlotId& y) { return x.AsTuple() <= y.AsTuple(); }
Expand Down Expand Up @@ -253,6 +259,7 @@ namespace NKikimr::NStorage {

// Last VDiskId reported to Node Whiteboard.
std::optional<TVDiskID> WhiteboardVDiskId;
ui64 WhiteboardInstanceGuid;

bool SlayInFlight = false;

Expand Down
15 changes: 13 additions & 2 deletions ydb/core/blobstorage/nodewarden/node_warden_vdisk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ namespace NKikimr::NStorage {
Send(WhiteboardId, new NNodeWhiteboard::TEvWhiteboard::TEvVDiskStateUpdate(vdiskId, groupInfo->GetStoragePoolName(),
vslotId.PDiskId, vslotId.VDiskSlotId, pdiskGuid, kind, donorMode, whiteboardInstanceGuid, std::move(donors)));
vdisk.WhiteboardVDiskId.emplace(vdiskId);
vdisk.WhiteboardInstanceGuid = whiteboardInstanceGuid;

// create an actor
auto *as = TActivationContext::ActorSystem();
Expand Down Expand Up @@ -281,9 +282,19 @@ namespace NKikimr::NStorage {

void TNodeWarden::Handle(TEvBlobStorage::TEvDropDonor::TPtr ev) {
auto *msg = ev->Get();
STLOG(PRI_INFO, BS_NODE, NW34, "TEvDropDonor", (VSlotId, TVSlotId(msg->NodeId, msg->PDiskId, msg->VSlotId)),
(VDiskId, msg->VDiskId));
const TVSlotId vslotId(msg->NodeId, msg->PDiskId, msg->VSlotId);
STLOG(PRI_INFO, BS_NODE, NW34, "TEvDropDonor", (VSlotId, vslotId), (VDiskId, msg->VDiskId));
SendDropDonorQuery(msg->NodeId, msg->PDiskId, msg->VSlotId, msg->VDiskId);

if (const auto it = LocalVDisks.find(vslotId); it != LocalVDisks.end()) {
const auto& vdisk = it->second;
if (vdisk.WhiteboardVDiskId) {
NKikimrBlobStorage::TVSlotId id;
vslotId.Serialize(&id);
Send(WhiteboardId, new NNodeWhiteboard::TEvWhiteboard::TEvVDiskDropDonors(*vdisk.WhiteboardVDiskId,
vdisk.WhiteboardInstanceGuid, {id}));
}
}
}

void TNodeWarden::UpdateGroupInfoForDisk(TVDiskRecord& vdisk, const TIntrusivePtr<TBlobStorageGroupInfo>& newInfo) {
Expand Down
1 change: 1 addition & 0 deletions ydb/core/grpc_services/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ target_link_libraries(ydb-core-grpc_services PUBLIC
cpp-client-resources
)
target_sources(ydb-core-grpc_services PRIVATE
${CMAKE_SOURCE_DIR}/ydb/core/grpc_services/audit_log.cpp
${CMAKE_SOURCE_DIR}/ydb/core/grpc_services/grpc_endpoint_publish_actor.cpp
${CMAKE_SOURCE_DIR}/ydb/core/grpc_services/grpc_helper.cpp
${CMAKE_SOURCE_DIR}/ydb/core/grpc_services/grpc_mon.cpp
Expand Down
21 changes: 21 additions & 0 deletions ydb/core/grpc_services/audit_log.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "defs.h"
#include "audit_log.h"

#include "base/base.h"

namespace NKikimr {
namespace NGRpcService {

void AuditLog(const IRequestProxyCtx* reqCtx, const TString& database,
const TString& subject, const TActorContext& ctx)
{
LOG_NOTICE_S(ctx, NKikimrServices::GRPC_SERVER, "AUDIT: "
<< "request name: " << reqCtx->GetRequestName()
<< ", database: " << database
<< ", peer: " << reqCtx->GetPeerName()
<< ", subject: " << subject);
}

}
}

12 changes: 12 additions & 0 deletions ydb/core/grpc_services/audit_log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

namespace NKikimr {
namespace NGRpcService {

class IRequestProxyCtx;

void AuditLog(const IRequestProxyCtx* reqCtx, const TString& database,
const TString& subject, const TActorContext& ctx);

}
}
10 changes: 10 additions & 0 deletions ydb/core/grpc_services/grpc_request_check_actor.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include "defs.h"
#include "audit_log.h"
#include "service_ratelimiter_events.h"
#include "local_rate_limiter.h"
#include "operation_helpers.h"
Expand Down Expand Up @@ -112,6 +113,10 @@ class TGrpcRequestCheckActor
}
}

if (AppData(ctx)->FeatureFlags.GetEnableGrpcAudit()) {
AuditLog(GrpcRequestBaseCtx_, CheckedDatabaseName_, GetSubject(), ctx);
}

// Simple rps limitation
static NRpcService::TRlConfig rpsRlConfig(
"serverless_rt_coordination_node_path",
Expand Down Expand Up @@ -205,6 +210,11 @@ class TGrpcRequestCheckActor
}

private:
TString GetSubject() const {
const auto sid = TBase::GetUserSID();
return sid ? sid : "no subject";
}

static NYql::TIssues GetRlIssues(const Ydb::RateLimiter::AcquireResourceResponse& resp) {
NYql::TIssues opIssues;
NYql::IssuesFromMessage(resp.operation().issues(), opIssues);
Expand Down
3 changes: 3 additions & 0 deletions ydb/core/mind/hive/balancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class THiveBalancer : public NActors::TActorBootstrapped<THiveBalancer>, public
if (RecheckOnFinish && MaxMovements != 0 && Movements >= MaxMovements) {
BLOG_D("Balancer initiated recheck");
Hive->ProcessTabletBalancer();
} else {
Send(Hive->SelfId(), new TEvPrivate::TEvBalancerOut());
}
return IActor::PassAway();
}
Expand Down Expand Up @@ -239,6 +241,7 @@ class THiveBalancer : public NActors::TActorBootstrapped<THiveBalancer>, public
tablets.emplace_back(tablet);
}
}
BLOG_TRACE("Balancer on node " << node->Id << ": " << tablets.size() << "/" << nodeTablets.size() << " tablets is suitable for balancing");
if (!tablets.empty()) {
switch (Hive->GetTabletBalanceStrategy()) {
case NKikimrConfig::THiveConfig::HIVE_TABLET_BALANCE_STRATEGY_OLD_WEIGHTED_RANDOM:
Expand Down
5 changes: 4 additions & 1 deletion ydb/core/mind/hive/hive_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct TEvPrivate {
EvUnlockTabletReconnectTimeout,
EvProcessPendingOperations,
EvRestartComplete,
EvBalancerOut,
EvEnd
};

Expand All @@ -37,7 +38,7 @@ struct TEvPrivate {
};

struct TEvProcessBootQueue : TEventLocal<TEvProcessBootQueue, EvProcessBootQueue> {};

struct TEvPostponeProcessBootQueue : TEventLocal<TEvPostponeProcessBootQueue, EvPostponeProcessBootQueue> {};

struct TEvProcessDisconnectNode : TEventLocal<TEvProcessDisconnectNode, EvProcessDisconnectNode> {
Expand Down Expand Up @@ -78,6 +79,8 @@ struct TEvPrivate {
};

struct TEvProcessPendingOperations : TEventLocal<TEvProcessPendingOperations, EvProcessPendingOperations> {};

struct TEvBalancerOut : TEventLocal<TEvBalancerOut, EvBalancerOut> {};
};

} // NHive
Expand Down
17 changes: 17 additions & 0 deletions ydb/core/mind/hive/hive_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ void THive::Handle(TEvPrivate::TEvProcessPendingOperations::TPtr&) {
BLOG_D("Handle ProcessPendingOperations");
}

void THive::Handle(TEvPrivate::TEvBalancerOut::TPtr&) {
BLOG_D("Handle BalancerOut");
}

void THive::Handle(TEvHive::TEvBootTablet::TPtr& ev) {
TTabletId tabletId = ev->Get()->Record.GetTabletID();
TTabletInfo* tablet = FindTablet(tabletId);
Expand Down Expand Up @@ -554,6 +558,14 @@ void THive::BuildCurrentConfig() {
for (const NKikimrConfig::THiveTabletPreference& tabletPreference : CurrentConfig.GetDefaultTabletPreference()) {
DefaultDataCentersPreference[tabletPreference.GetType()] = tabletPreference.GetDataCentersPreference();
}
BalancerIgnoreTabletTypes.clear();
for (auto i : CurrentConfig.GetBalancerIgnoreTabletTypes()) {
const auto type = TTabletTypes::EType(i);
if (IsValidTabletType(type)) {
BalancerIgnoreTabletTypes.emplace_back(type);
}
}
MakeTabletTypeSet(BalancerIgnoreTabletTypes);
}

void THive::Cleanup() {
Expand Down Expand Up @@ -1612,6 +1624,7 @@ void THive::FillTabletInfo(NKikimrHive::TEvResponseHiveInfo& response, ui64 tabl
auto& tabletInfo = *response.AddTablets();
tabletInfo.SetTabletID(tabletId);
tabletInfo.SetTabletType(info->Type);
tabletInfo.SetObjectId(info->ObjectId);
tabletInfo.SetState(static_cast<ui32>(info->State));
tabletInfo.SetTabletBootMode(info->BootMode);
tabletInfo.SetVolatileState(info->GetVolatileState());
Expand All @@ -1620,6 +1633,9 @@ void THive::FillTabletInfo(NKikimrHive::TEvResponseHiveInfo& response, ui64 tabl
tabletInfo.MutableTabletOwner()->SetOwnerIdx(info->Owner.second);
tabletInfo.SetGeneration(info->KnownGeneration);
tabletInfo.MutableObjectDomain()->CopyFrom(info->ObjectDomain);
if (info->BalancerPolicy != NKikimrHive::EBalancerPolicy::POLICY_BALANCE) {
tabletInfo.SetBalancerPolicy(info->BalancerPolicy);
}
if (!info->IsRunning()) {
tabletInfo.SetLastAliveTimestamp(info->Statistics.GetLastAliveTimestamp());
}
Expand Down Expand Up @@ -2437,6 +2453,7 @@ STFUNC(THive::StateWork) {
hFunc(NSysView::TEvSysView::TEvGetTabletsRequest, Handle);
hFunc(TEvHive::TEvRequestTabletOwners, Handle);
hFunc(TEvHive::TEvTabletOwnersReply, Handle);
hFunc(TEvPrivate::TEvBalancerOut, Handle);
default:
if (!HandleDefaultEvents(ev, ctx)) {
BLOG_W("THive::StateWork unhandled event type: " << ev->GetTypeRewrite()
Expand Down
12 changes: 12 additions & 0 deletions ydb/core/mind/hive/hive_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ TString GetConditionalRedString(const TString& str, bool condition);
TString GetDataCenterName(ui64 dataCenterId);
TString LongToShortTabletName(const TString& longTabletName);
TString GetLocationString(const NActors::TNodeLocation& location);
void MakeTabletTypeSet(std::vector<TTabletTypes::EType>& list);
bool IsValidTabletType(TTabletTypes::EType type);

class THive : public TActor<THive>, public TTabletExecutedFlat, public THiveSharedSettings {
public:
Expand Down Expand Up @@ -404,6 +406,9 @@ class THive : public TActor<THive>, public TTabletExecutedFlat, public THiveShar
std::unordered_map<TDataCenterId, std::unordered_set<TNodeId>> RegisteredDataCenterNodes;
std::unordered_set<TNodeId> ConnectedNodes;

// normalized to be sorted list of unique values
std::vector<TTabletTypes::EType> BalancerIgnoreTabletTypes; // built from CurrentConfig

// to be removed later
bool TabletOwnersSynced = false;
// to be removed later
Expand Down Expand Up @@ -482,6 +487,7 @@ class THive : public TActor<THive>, public TTabletExecutedFlat, public THiveShar
void Handle(TEvPrivate::TEvProcessTabletBalancer::TPtr&);
void Handle(TEvPrivate::TEvUnlockTabletReconnectTimeout::TPtr&);
void Handle(TEvPrivate::TEvProcessPendingOperations::TPtr&);
void Handle(TEvPrivate::TEvBalancerOut::TPtr&);
void Handle(TEvTxProxySchemeCache::TEvNavigateKeySetResult::TPtr& ev);
void Handle(NConsole::TEvConsole::TEvConfigNotificationRequest::TPtr& ev);
void Handle(NConsole::TEvConfigsDispatcher::TEvSetConfigSubscriptionResponse::TPtr& ev);
Expand Down Expand Up @@ -748,6 +754,12 @@ class THive : public TActor<THive>, public TTabletExecutedFlat, public THiveShar
return initialMaximum;
}

bool IsInBalancerIgnoreList(TTabletTypes::EType type) const {
const auto& ignoreList = BalancerIgnoreTabletTypes;
auto found = std::find(ignoreList.begin(), ignoreList.end(), type);
return (found != ignoreList.end());
}

static void ActualizeRestartStatistics(google::protobuf::RepeatedField<google::protobuf::uint64>& restartTimestamps, ui64 barrier);
static bool IsSystemTablet(TTabletTypes::EType type);

Expand Down
5 changes: 4 additions & 1 deletion ydb/core/mind/hive/hive_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ struct Schema : NIceDb::Schema {
struct DataCentersPreference : Column<121, NScheme::NTypeIds::String> { using Type = NKikimrHive::TDataCentersPreference; };
struct AllowedDataCenterIds : Column<122, NScheme::NTypeIds::String> { using Type = TVector<TString>; };

struct BalancerPolicy : Column<123, NScheme::NTypeIds::Uint64> { using Type = NKikimrHive::EBalancerPolicy; static constexpr NKikimrHive::EBalancerPolicy Default = NKikimrHive::EBalancerPolicy::POLICY_BALANCE; };

using TKey = TableKey<ID>;
using TColumns = TableColumns<
ID,
Expand All @@ -118,7 +120,8 @@ struct Schema : NIceDb::Schema {
ReassignReason,
Statistics,
DataCentersPreference,
AllowedDataCenterIds
AllowedDataCenterIds,
BalancerPolicy
>;
};

Expand Down
11 changes: 11 additions & 0 deletions ydb/core/mind/hive/hive_statics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,5 +340,16 @@ TString GetLocationString(const NActors::TNodeLocation& location) {
return proto.ShortDebugString();
}

void MakeTabletTypeSet(std::vector<TTabletTypes::EType>& list) {
std::sort(list.begin(), list.end());
list.erase(std::unique(list.begin(), list.end()), list.end());
}

bool IsValidTabletType(TTabletTypes::EType type) {
return (type > TTabletTypes::Unknown
&& type < TTabletTypes::Reserved40
);
}

} // NHive
} // NKikimr
Loading

0 comments on commit 11bc401

Please sign in to comment.