Skip to content

Commit

Permalink
[Backport 2.6] [#9606] [docdb] Add flag --force for command delete_ta…
Browse files Browse the repository at this point in the history
…blet to set state TABLET_DATA_DELETED for tool yb-ts-cli

Summary:
Add flag --force for command delete_tablet to set state TABLET_DATA_DELETED for tool yb-ts-cli

yb-ts-cli delete_tablet sends RPC with TABLET_DATA_TOMBSTONED which doesn't delete tablet from tablet map.
Tablet with state TABLET_DATA_TOMBSTONED can't be moved to another drive.

Tablet superblock with state TABLET_DATA_DELETED will be cleaned up on node restart.

Original commit: D13272 / 48e19e9

Test Plan:
Jenkins: rebase: 2.6

ybd --gtest_filter TabletServerTest.TestDeleteTablet
ybd --cxx-test integration-tests_delete_table-test

Tested on local cluster with following steps:
yb-ctl create --replication_factor 3 --data_dir /tmp/yb-data --num_drives 4 --master_flags="load_balancer_drive_aware=false"
ycqlsh
ycqlsh> CREATE keyspace ybdemo_keyspace;
ycqlsh> CREATE TABLE IF NOT EXISTS ybdemo_keyspace.CassandraKeyValue (k varchar, v blob, primary key (k)) WITH TABLETS = 24;
yb-ctl add_node --data_dir /tmp/yb-data
ls /tmp/yb-data/node-1/d*/yb-data/tserver/data/rocksdb/table-* | grep -v intents | grep -v snapshots

```
/tmp/yb-data/node-1/disk-1/yb-data/tserver/data/rocksdb/table-a147010f8151462fba2912023b6672dd:
tablet-9a88881b5740447b9bebab8860e1a4ff
tablet-d880a55cdb1a41d5bf3c5bb974865878
tablet-fe00bcac6c3b498b8d08a83fec971549

/tmp/yb-data/node-1/disk-2/yb-data/tserver/data/rocksdb/table-a147010f8151462fba2912023b6672dd:
tablet-174da60f6df146f6984cf0146d519e29
tablet-38859bebba3148ceb51e549a398aec76
tablet-67415b883f89440785ffc922f0680821
tablet-960725b538004086bb92faecd5db7600
tablet-9ddb8803aeac43f7969136e720b0f45c
tablet-ead9026518624a859477d06a57359882

/tmp/yb-data/node-1/disk-3/yb-data/tserver/data/rocksdb/table-a147010f8151462fba2912023b6672dd:
tablet-1a214b020e45419ba9f5c9e07030af28
tablet-b3711c44885940e0a32659efdb698573
tablet-f348c53ce1e74056b7e2a13fd4eb623c

/tmp/yb-data/node-1/disk-4/yb-data/tserver/data/rocksdb/table-a147010f8151462fba2912023b6672dd:
tablet-472fd833b8aa45c79568a651a96be08d
tablet-5ab420c1df5347d5a7bb44e5374bcd46
tablet-6cb5ad3613a5428c8fcf7587c7862a86
tablet-a484ed5737fc4e8190d5782dab3b116c
tablet-b6970e3f22a84907936549b87014105a
tablet-e85ec01f16d34b5a87db55d09d66c9e9
```
yb-ts-cli -timeout_ms 600000 --server_address=127.0.0.1:9100 delete_tablet -force e85ec01f16d34b5a87db55d09d66c9e9 test
yb-ctl --data_dir /tmp/yb-data restart_node 1
ls /tmp/yb-data/node-1/d*/yb-data/tserver/data/rocksdb/table-* | grep -v intents | grep -v snapshots

```
/tmp/yb-data/node-1/disk-1/yb-data/tserver/data/rocksdb/table-a147010f8151462fba2912023b6672dd:
tablet-9a88881b5740447b9bebab8860e1a4ff
tablet-d880a55cdb1a41d5bf3c5bb974865878
tablet-e85ec01f16d34b5a87db55d09d66c9e9
tablet-fe00bcac6c3b498b8d08a83fec971549

/tmp/yb-data/node-1/disk-2/yb-data/tserver/data/rocksdb/table-a147010f8151462fba2912023b6672dd:
tablet-174da60f6df146f6984cf0146d519e29
tablet-38859bebba3148ceb51e549a398aec76
tablet-67415b883f89440785ffc922f0680821
tablet-960725b538004086bb92faecd5db7600
tablet-9ddb8803aeac43f7969136e720b0f45c
tablet-ead9026518624a859477d06a57359882

/tmp/yb-data/node-1/disk-3/yb-data/tserver/data/rocksdb/table-a147010f8151462fba2912023b6672dd:
tablet-1a214b020e45419ba9f5c9e07030af28
tablet-b3711c44885940e0a32659efdb698573
tablet-f348c53ce1e74056b7e2a13fd4eb623c

/tmp/yb-data/node-1/disk-4/yb-data/tserver/data/rocksdb/table-a147010f8151462fba2912023b6672dd:
tablet-472fd833b8aa45c79568a651a96be08d
tablet-5ab420c1df5347d5a7bb44e5374bcd46
tablet-6cb5ad3613a5428c8fcf7587c7862a86
tablet-a484ed5737fc4e8190d5782dab3b116c
tablet-b6970e3f22a84907936549b87014105a
```

Reviewers: sergei, bogdan

Reviewed By: bogdan

Subscribers: ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D13607
  • Loading branch information
mikhpolitov committed Oct 26, 2021
1 parent b3fb954 commit 797088d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 41 deletions.
22 changes: 14 additions & 8 deletions src/yb/tools/ts-cli.cc
Expand Up @@ -103,9 +103,12 @@ DEFINE_string(server_address, "localhost",
"Address of server to run against");
DEFINE_int64(timeout_ms, 1000 * 60, "RPC timeout in milliseconds");

DEFINE_bool(force, false, "If true, allows the set_flag command to set a flag "
DEFINE_bool(force, false, "set_flag: If true, allows command to set a flag "
"which is not explicitly marked as runtime-settable. Such flag changes may be "
"simply ignored on the server, or may cause the server to crash.");
"simply ignored on the server, or may cause the server to crash.\n"
"delete_tablet: If true, command will delete the tablet and remove the tablet "
"from the memory, otherwise tablet metadata will be kept in memory with state "
"TOMBSTONED.");

DEFINE_string(certs_dir_name, "",
"Directory with certificates to use for secure server connection.");
Expand Down Expand Up @@ -185,7 +188,8 @@ class TsAdminClient {
// Delete a tablet replica from the specified peer.
// The 'reason' string is passed to the tablet server, used for logging.
Status DeleteTablet(const std::string& tablet_id,
const std::string& reason);
const std::string& reason,
tablet::TabletDataState delete_type);

// Sets hybrid_time to the value of the tablet server's current hybrid_time.
Status CurrentHybridTime(uint64_t* hybrid_time);
Expand Down Expand Up @@ -390,7 +394,8 @@ Status TsAdminClient::DumpTablet(const std::string& tablet_id) {
}

Status TsAdminClient::DeleteTablet(const string& tablet_id,
const string& reason) {
const string& reason,
tablet::TabletDataState delete_type) {
ServerStatusPB status_pb;
RETURN_NOT_OK(GetStatus(&status_pb));

Expand All @@ -401,7 +406,7 @@ Status TsAdminClient::DeleteTablet(const string& tablet_id,
req.set_tablet_id(tablet_id);
req.set_dest_uuid(status_pb.node_instance().permanent_uuid());
req.set_reason(reason);
req.set_delete_type(tablet::TABLET_DATA_TOMBSTONED);
req.set_delete_type(delete_type);
rpc.set_timeout(timeout_);
RETURN_NOT_OK_PREPEND(ts_admin_proxy_->DeleteTablet(req, &resp, &rpc),
"DeleteTablet() failed");
Expand Down Expand Up @@ -487,7 +492,7 @@ void SetUsage(const char* argv0) {
<< " " << kRefreshFlagsOp << "\n"
<< " " << kTabletStateOp << " <tablet_id>\n"
<< " " << kDumpTabletOp << " <tablet_id>\n"
<< " " << kDeleteTabletOp << " <tablet_id> <reason string>\n"
<< " " << kDeleteTabletOp << " [-force] <tablet_id> <reason string>\n"
<< " " << kCurrentHybridTime << "\n"
<< " " << kStatus << "\n"
<< " " << kCountIntents << "\n"
Expand Down Expand Up @@ -617,8 +622,9 @@ static int TsCliMain(int argc, char** argv) {

string tablet_id = argv[2];
string reason = argv[3];

RETURN_NOT_OK_PREPEND_FROM_MAIN(client.DeleteTablet(tablet_id, reason),
tablet::TabletDataState state = FLAGS_force ? tablet::TABLET_DATA_DELETED :
tablet::TABLET_DATA_TOMBSTONED;
RETURN_NOT_OK_PREPEND_FROM_MAIN(client.DeleteTablet(tablet_id, reason, state),
"Unable to delete tablet");
} else if (op == kCurrentHybridTime) {
CHECK_ARGC_OR_RETURN_WITH_USAGE(op, 2);
Expand Down
62 changes: 31 additions & 31 deletions src/yb/tserver/tablet_server-test.cc
Expand Up @@ -103,6 +103,30 @@ class TabletServerTest : public TabletServerTestBase {
TabletServerTestBase::SetUp();
StartTabletServer();
}

CHECKED_STATUS CallDeleteTablet(const std::string& uuid,
const char* tablet_id,
tablet::TabletDataState state) {
DeleteTabletRequestPB req;
DeleteTabletResponsePB resp;
RpcController rpc;

req.set_dest_uuid(uuid);
req.set_tablet_id(tablet_id);
req.set_delete_type(state);

// Send the call
{
SCOPED_TRACE(req.DebugString());
RETURN_NOT_OK(admin_proxy_->DeleteTablet(req, &resp, &rpc));
SCOPED_TRACE(resp.DebugString());
if (resp.has_error()) {
auto status = StatusFromPB(resp.error().status());
RETURN_NOT_OK(status);
}
}
return Status::OK();
}
};

TEST_F(TabletServerTest, TestPingServer) {
Expand Down Expand Up @@ -591,21 +615,9 @@ TEST_F(TabletServerTest, TestDeleteTablet) {
tablet_peer_.reset();
tablet.reset();

DeleteTabletRequestPB req;
DeleteTabletResponsePB resp;
RpcController rpc;

req.set_dest_uuid(mini_server_->server()->fs_manager()->uuid());
req.set_tablet_id(kTabletId);
req.set_delete_type(tablet::TABLET_DATA_DELETED);

// Send the call
{
SCOPED_TRACE(req.DebugString());
ASSERT_OK(admin_proxy_->DeleteTablet(req, &resp, &rpc));
SCOPED_TRACE(resp.DebugString());
ASSERT_FALSE(resp.has_error());
}
ASSERT_OK(CallDeleteTablet(mini_server_->server()->fs_manager()->uuid(),
kTabletId,
tablet::TABLET_DATA_DELETED));

// Verify that the tablet is removed from the tablet map
ASSERT_FALSE(mini_server_->server()->tablet_manager()->LookupTablet(kTabletId, &tablet));
Expand All @@ -625,22 +637,10 @@ TEST_F(TabletServerTest, TestDeleteTablet) {
}

TEST_F(TabletServerTest, TestDeleteTablet_TabletNotCreated) {
DeleteTabletRequestPB req;
DeleteTabletResponsePB resp;
RpcController rpc;

req.set_dest_uuid(mini_server_->server()->fs_manager()->uuid());
req.set_tablet_id("NotPresentTabletId");
req.set_delete_type(tablet::TABLET_DATA_DELETED);

// Send the call
{
SCOPED_TRACE(req.DebugString());
ASSERT_OK(admin_proxy_->DeleteTablet(req, &resp, &rpc));
SCOPED_TRACE(resp.DebugString());
ASSERT_TRUE(resp.has_error());
ASSERT_EQ(TabletServerErrorPB::TABLET_NOT_FOUND, resp.error().code());
}
Status s = CallDeleteTablet(mini_server_->server()->fs_manager()->uuid(),
"NotPresentTabletId",
tablet::TABLET_DATA_DELETED);
ASSERT_TRUE(s.IsNotFound()) << s.ToString();
}

// Test that with concurrent requests to delete the same tablet, one wins and
Expand Down
4 changes: 2 additions & 2 deletions src/yb/tserver/ts_tablet_manager.cc
Expand Up @@ -1052,8 +1052,8 @@ Status TSTabletManager::StartRemoteBootstrap(const StartRemoteBootstrapRequestPB
// getting to a TABLET_DATA_READY state fail.

// Registering a non-initialized TabletPeer offers visibility through the Web UI.
RegisterTabletPeerMode mode = replacing_tablet ? REPLACEMENT_PEER : NEW_PEER;
TabletPeerPtr tablet_peer = VERIFY_RESULT(CreateAndRegisterTabletPeer(meta, mode));
TabletPeerPtr tablet_peer = VERIFY_RESULT(
CreateAndRegisterTabletPeer(meta, replacing_tablet ? REPLACEMENT_PEER : NEW_PEER));
MarkTabletBeingRemoteBootstrapped(tablet_peer->tablet_id(),
tablet_peer->tablet_metadata()->table_id());

Expand Down

0 comments on commit 797088d

Please sign in to comment.