You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by mp...@apache.org on 2017/05/04 22:14:26 UTC
[1/5] kudu git commit: Rename TabletPeer to TabletReplica
Repository: kudu
Updated Branches:
refs/heads/master 14e9d3d26 -> 7f72105b7
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/tablet_service.h
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_service.h b/src/kudu/tserver/tablet_service.h
index 8a9f102..f378e34 100644
--- a/src/kudu/tserver/tablet_service.h
+++ b/src/kudu/tserver/tablet_service.h
@@ -38,14 +38,14 @@ class ServerBase;
namespace tablet {
class Tablet;
-class TabletPeer;
+class TabletReplica;
class TransactionState;
} // namespace tablet
namespace tserver {
class ScanResultCollector;
-class TabletPeerLookupIf;
+class TabletReplicaLookupIf;
class TabletServer;
class TabletServiceImpl : public TabletServerServiceIf {
@@ -88,7 +88,7 @@ class TabletServiceImpl : public TabletServerServiceIf {
virtual void Shutdown() OVERRIDE;
private:
- Status HandleNewScanRequest(tablet::TabletPeer* tablet_peer,
+ Status HandleNewScanRequest(tablet::TabletReplica* tablet_replica,
const ScanRequestPB* req,
const rpc::RpcContext* rpc_context,
ScanResultCollector* result_collector,
@@ -105,7 +105,7 @@ class TabletServiceImpl : public TabletServerServiceIf {
Status HandleScanAtSnapshot(const NewScanRequestPB& scan_pb,
const rpc::RpcContext* rpc_context,
const Schema& projection,
- tablet::TabletPeer* tablet_peer,
+ tablet::TabletReplica* tablet_replica,
gscoped_ptr<RowwiseIterator>* iter,
Timestamp* snap_timestamp);
@@ -139,7 +139,7 @@ class TabletServiceAdminImpl : public TabletServerAdminServiceIf {
class ConsensusServiceImpl : public consensus::ConsensusServiceIf {
public:
ConsensusServiceImpl(server::ServerBase* server,
- TabletPeerLookupIf* tablet_manager);
+ TabletReplicaLookupIf* tablet_manager);
virtual ~ConsensusServiceImpl();
@@ -189,7 +189,7 @@ class ConsensusServiceImpl : public consensus::ConsensusServiceIf {
private:
server::ServerBase* server_;
- TabletPeerLookupIf* tablet_manager_;
+ TabletReplicaLookupIf* tablet_manager_;
};
} // namespace tserver
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/ts_tablet_manager-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/ts_tablet_manager-test.cc b/src/kudu/tserver/ts_tablet_manager-test.cc
index 9aeca50..7b290bf 100644
--- a/src/kudu/tserver/ts_tablet_manager-test.cc
+++ b/src/kudu/tserver/ts_tablet_manager-test.cc
@@ -25,7 +25,7 @@
#include "kudu/consensus/metadata.pb.h"
#include "kudu/fs/fs_manager.h"
#include "kudu/master/master.pb.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tablet/tablet-test-util.h"
#include "kudu/tserver/heartbeater.h"
#include "kudu/tserver/mini_tablet_server.h"
@@ -46,7 +46,7 @@ using consensus::kInvalidOpIdIndex;
using consensus::RaftConfigPB;
using master::ReportedTabletPB;
using master::TabletReportPB;
-using tablet::TabletPeer;
+using tablet::TabletReplica;
static const char* const kTabletId = "my-tablet-id";
@@ -78,22 +78,22 @@ class TsTabletManagerTest : public KuduTest {
Status CreateNewTablet(const std::string& tablet_id,
const Schema& schema,
- scoped_refptr<tablet::TabletPeer>* out_tablet_peer) {
+ scoped_refptr<tablet::TabletReplica>* out_tablet_replica) {
Schema full_schema = SchemaBuilder(schema).Build();
std::pair<PartitionSchema, Partition> partition = tablet::CreateDefaultPartition(full_schema);
- scoped_refptr<tablet::TabletPeer> tablet_peer;
+ scoped_refptr<tablet::TabletReplica> tablet_replica;
RETURN_NOT_OK(tablet_manager_->CreateNewTablet(tablet_id, tablet_id, partition.second,
tablet_id,
full_schema, partition.first,
config_,
- &tablet_peer));
- if (out_tablet_peer) {
- (*out_tablet_peer) = tablet_peer;
+ &tablet_replica));
+ if (out_tablet_replica) {
+ (*out_tablet_replica) = tablet_replica;
}
- RETURN_NOT_OK(tablet_peer->WaitUntilConsensusRunning(MonoDelta::FromMilliseconds(2000)));
- return tablet_peer->consensus()->WaitUntilLeaderForTests(MonoDelta::FromSeconds(10));
+ RETURN_NOT_OK(tablet_replica->WaitUntilConsensusRunning(MonoDelta::FromMilliseconds(2000)));
+ return tablet_replica->consensus()->WaitUntilLeaderForTests(MonoDelta::FromSeconds(10));
}
void GenerateFullTabletReport(TabletReportPB* report) {
@@ -126,10 +126,10 @@ class TsTabletManagerTest : public KuduTest {
TEST_F(TsTabletManagerTest, TestCreateTablet) {
// Create a new tablet.
- scoped_refptr<TabletPeer> peer;
- ASSERT_OK(CreateNewTablet(kTabletId, schema_, &peer));
- ASSERT_EQ(kTabletId, peer->tablet()->tablet_id());
- peer.reset();
+ scoped_refptr<TabletReplica> replica;
+ ASSERT_OK(CreateNewTablet(kTabletId, schema_, &replica));
+ ASSERT_EQ(kTabletId, replica->tablet()->tablet_id());
+ replica.reset();
// Re-load the tablet manager from the filesystem.
LOG(INFO) << "Shutting down tablet manager";
@@ -142,8 +142,8 @@ TEST_F(TsTabletManagerTest, TestCreateTablet) {
tablet_manager_ = mini_server_->server()->tablet_manager();
// Ensure that the tablet got re-loaded and re-opened off disk.
- ASSERT_TRUE(tablet_manager_->LookupTablet(kTabletId, &peer));
- ASSERT_EQ(kTabletId, peer->tablet()->tablet_id());
+ ASSERT_TRUE(tablet_manager_->LookupTablet(kTabletId, &replica));
+ ASSERT_EQ(kTabletId, replica->tablet()->tablet_id());
}
static void AssertMonotonicReportSeqno(int64_t* report_seqno,
@@ -228,7 +228,7 @@ TEST_F(TsTabletManagerTest, TestTabletReports) {
ASSERT_OK(CreateNewTablet("tablet-2", schema_, nullptr));
// Wait up to 10 seconds to get a tablet report from tablet-2.
- // TabletPeer does not mark tablets dirty until after it commits the
+ // TabletReplica does not mark tablets dirty until after it commits the
// initial configuration change, so there is also a window for tablet-1 to
// have been marked dirty since the last report.
MonoDelta timeout(MonoDelta::FromSeconds(10));
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/ts_tablet_manager.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/ts_tablet_manager.cc b/src/kudu/tserver/ts_tablet_manager.cc
index 9bfa941..45c7016 100644
--- a/src/kudu/tserver/ts_tablet_manager.cc
+++ b/src/kudu/tserver/ts_tablet_manager.cc
@@ -44,7 +44,7 @@
#include "kudu/tablet/tablet.pb.h"
#include "kudu/tablet/tablet_bootstrap.h"
#include "kudu/tablet/tablet_metadata.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tserver/heartbeater.h"
#include "kudu/tserver/tablet_copy_client.h"
#include "kudu/tserver/tablet_server.h"
@@ -147,7 +147,7 @@ using tablet::TABLET_DATA_READY;
using tablet::TABLET_DATA_TOMBSTONED;
using tablet::TabletDataState;
using tablet::TabletMetadata;
-using tablet::TabletPeer;
+using tablet::TabletReplica;
using tablet::TabletStatusListener;
using tablet::TabletStatusPB;
using tserver::TabletCopyClient;
@@ -225,7 +225,7 @@ Status TSTabletManager::Init() {
CHECK_OK(StartTabletStateTransitionUnlocked(meta->tablet_id(), "opening tablet", &deleter));
}
- scoped_refptr<TabletPeer> tablet_peer = CreateAndRegisterTabletPeer(meta, NEW_PEER);
+ scoped_refptr<TabletReplica> replica = CreateAndRegisterTabletReplica(meta, NEW_REPLICA);
RETURN_NOT_OK(open_tablet_pool_->SubmitFunc(boost::bind(&TSTabletManager::OpenTablet,
this, meta, deleter)));
}
@@ -260,7 +260,7 @@ Status TSTabletManager::CreateNewTablet(const string& table_id,
const Schema& schema,
const PartitionSchema& partition_schema,
RaftConfigPB config,
- scoped_refptr<TabletPeer>* tablet_peer) {
+ scoped_refptr<TabletReplica>* replica) {
CHECK_EQ(state(), MANAGER_RUNNING);
CHECK(IsRaftConfigMember(server_->instance_pb().permanent_uuid(), config));
@@ -275,7 +275,7 @@ Status TSTabletManager::CreateNewTablet(const string& table_id,
TRACE("Acquired tablet manager lock");
// Sanity check that the tablet isn't already registered.
- scoped_refptr<TabletPeer> junk;
+ scoped_refptr<TabletReplica> junk;
if (LookupTabletUnlocked(tablet_id, &junk)) {
return Status::AlreadyPresent("Tablet already registered", tablet_id);
}
@@ -300,19 +300,19 @@ Status TSTabletManager::CreateNewTablet(const string& table_id,
"Couldn't create tablet metadata");
// We must persist the consensus metadata to disk before starting a new
- // tablet's TabletPeer and Consensus implementation.
+ // tablet's TabletReplica and Consensus implementation.
unique_ptr<ConsensusMetadata> cmeta;
RETURN_NOT_OK_PREPEND(ConsensusMetadata::Create(fs_manager_, tablet_id, fs_manager_->uuid(),
config, consensus::kMinimumTerm, &cmeta),
"Unable to create new ConsensusMeta for tablet " + tablet_id);
- scoped_refptr<TabletPeer> new_peer = CreateAndRegisterTabletPeer(meta, NEW_PEER);
+ scoped_refptr<TabletReplica> new_replica = CreateAndRegisterTabletReplica(meta, NEW_REPLICA);
// We can run this synchronously since there is nothing to bootstrap.
RETURN_NOT_OK(open_tablet_pool_->SubmitFunc(boost::bind(&TSTabletManager::OpenTablet,
this, meta, deleter)));
- if (tablet_peer) {
- *tablet_peer = new_peer;
+ if (replica) {
+ *replica = new_replica;
}
return Status::OK();
}
@@ -421,14 +421,14 @@ void TSTabletManager::RunTabletCopy(
CALLBACK_RETURN_NOT_OK(HostPortFromPB(req->copy_peer_addr(), ©_source_addr));
int64_t leader_term = req->caller_term();
- scoped_refptr<TabletPeer> old_tablet_peer;
+ scoped_refptr<TabletReplica> old_replica;
scoped_refptr<TabletMetadata> meta;
bool replacing_tablet = false;
scoped_refptr<TransitionInProgressDeleter> deleter;
{
std::lock_guard<rw_spinlock> lock(lock_);
- if (LookupTabletUnlocked(tablet_id, &old_tablet_peer)) {
- meta = old_tablet_peer->tablet_metadata();
+ if (LookupTabletUnlocked(tablet_id, &old_replica)) {
+ meta = old_replica->tablet_metadata();
replacing_tablet = true;
}
Status ret = StartTabletStateTransitionUnlocked(tablet_id, "copying tablet",
@@ -440,7 +440,7 @@ void TSTabletManager::RunTabletCopy(
}
if (replacing_tablet) {
- // Make sure the existing tablet peer is shut down and tombstoned.
+ // Make sure the existing tablet replica is shut down and tombstoned.
TabletDataState data_state = meta->tablet_data_state();
switch (data_state) {
case TABLET_DATA_COPYING:
@@ -453,7 +453,7 @@ void TSTabletManager::RunTabletCopy(
break;
}
case TABLET_DATA_READY: {
- Log* log = old_tablet_peer->log();
+ Log* log = old_replica->log();
if (!log) {
CALLBACK_AND_RETURN(
Status::IllegalState("Log unavailable. Tablet is not running", tablet_id));
@@ -464,7 +464,7 @@ void TSTabletManager::RunTabletCopy(
CALLBACK_RETURN_NOT_OK(CheckLeaderTermNotLower(tablet_id, leader_term, last_logged_term));
// Tombstone the tablet and store the last-logged OpId.
- old_tablet_peer->Shutdown();
+ old_replica->Shutdown();
// TODO(mpercy): Because we begin shutdown of the tablet after we check our
// last-logged term against the leader's term, there may be operations
// in flight and it may be possible for the same check in the tablet
@@ -507,9 +507,9 @@ void TSTabletManager::RunTabletCopy(
// state, and we need to tombtone the tablet if additional steps prior to
// 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;
- scoped_refptr<TabletPeer> tablet_peer = CreateAndRegisterTabletPeer(meta, mode);
+ // Registering a non-initialized TabletReplica offers visibility through the Web UI.
+ RegisterTabletReplicaMode mode = replacing_tablet ? REPLACEMENT_REPLICA : NEW_REPLICA;
+ scoped_refptr<TabletReplica> replica = CreateAndRegisterTabletReplica(meta, mode);
// Now we invoke the StartTabletCopy callback and respond success to the
// remote caller. Then we proceed to do most of the actual tablet copying work.
@@ -521,7 +521,7 @@ void TSTabletManager::RunTabletCopy(
// From this point onward, we do not notify the caller about progress or success.
// Download all of the remote files.
- Status s = tc_client.FetchAll(implicit_cast<TabletStatusListener*>(tablet_peer.get()));
+ Status s = tc_client.FetchAll(implicit_cast<TabletStatusListener*>(replica.get()));
if (!s.ok()) {
LOG(WARNING) << LogPrefix(tablet_id) << "Tablet Copy: Unable to fetch data from remote peer "
<< kSrcPeerInfo << ": " << s.ToString();
@@ -539,21 +539,22 @@ void TSTabletManager::RunTabletCopy(
return;
}
- // We don't tombstone the tablet if opening the tablet fails, because on next
// startup it's still in a valid, fully-copied state.
OpenTablet(meta, deleter);
}
-// Create and register a new TabletPeer, given tablet metadata.
-scoped_refptr<TabletPeer> TSTabletManager::CreateAndRegisterTabletPeer(
- const scoped_refptr<TabletMetadata>& meta, RegisterTabletPeerMode mode) {
- scoped_refptr<TabletPeer> tablet_peer(
- new TabletPeer(meta,
- local_peer_pb_,
- apply_pool_.get(),
- Bind(&TSTabletManager::MarkTabletDirty, Unretained(this), meta->tablet_id())));
- RegisterTablet(meta->tablet_id(), tablet_peer, mode);
- return tablet_peer;
+// Create and register a new TabletReplica, given tablet metadata.
+scoped_refptr<TabletReplica> TSTabletManager::CreateAndRegisterTabletReplica(
+ const scoped_refptr<TabletMetadata>& meta, RegisterTabletReplicaMode mode) {
+ scoped_refptr<TabletReplica> replica(
+ new TabletReplica(meta,
+ local_peer_pb_,
+ apply_pool_.get(),
+ Bind(&TSTabletManager::MarkTabletDirty,
+ Unretained(this),
+ meta->tablet_id())));
+ RegisterTablet(meta->tablet_id(), replica, mode);
+ return replica;
}
Status TSTabletManager::DeleteTablet(
@@ -571,7 +572,7 @@ Status TSTabletManager::DeleteTablet(
TRACE("Deleting tablet $0", tablet_id);
- scoped_refptr<TabletPeer> tablet_peer;
+ scoped_refptr<TabletReplica> replica;
scoped_refptr<TransitionInProgressDeleter> deleter;
{
// Acquire the lock in exclusive mode as we'll add a entry to the
@@ -580,7 +581,7 @@ Status TSTabletManager::DeleteTablet(
TRACE("Acquired tablet manager lock");
RETURN_NOT_OK(CheckRunningUnlocked(error_code));
- if (!LookupTabletUnlocked(tablet_id, &tablet_peer)) {
+ if (!LookupTabletUnlocked(tablet_id, &replica)) {
*error_code = TabletServerErrorPB::TABLET_NOT_FOUND;
return Status::NotFound("Tablet not found", tablet_id);
}
@@ -594,7 +595,7 @@ Status TSTabletManager::DeleteTablet(
// If the tablet is already deleted, the CAS check isn't possible because
// consensus and therefore the log is not available.
- TabletDataState data_state = tablet_peer->tablet_metadata()->tablet_data_state();
+ TabletDataState data_state = replica->tablet_metadata()->tablet_data_state();
bool tablet_deleted = (data_state == TABLET_DATA_DELETED || data_state == TABLET_DATA_TOMBSTONED);
// They specified an "atomic" delete. Check the committed config's opid_index.
@@ -603,7 +604,7 @@ Status TSTabletManager::DeleteTablet(
// restarting the tablet if the local replica committed a higher config
// change op during that time, or potentially something else more invasive.
if (cas_config_opid_index_less_or_equal && !tablet_deleted) {
- scoped_refptr<consensus::Consensus> consensus = tablet_peer->shared_consensus();
+ scoped_refptr<consensus::Consensus> consensus = replica->shared_consensus();
if (!consensus) {
*error_code = TabletServerErrorPB::TABLET_NOT_RUNNING;
return Status::IllegalState("Consensus not available. Tablet shutting down");
@@ -618,25 +619,25 @@ Status TSTabletManager::DeleteTablet(
}
}
- tablet_peer->Shutdown();
+ replica->Shutdown();
boost::optional<OpId> opt_last_logged_opid;
- if (tablet_peer->log()) {
+ if (replica->log()) {
OpId last_logged_opid;
- tablet_peer->log()->GetLatestEntryOpId(&last_logged_opid);
+ replica->log()->GetLatestEntryOpId(&last_logged_opid);
opt_last_logged_opid = last_logged_opid;
}
- Status s = DeleteTabletData(tablet_peer->tablet_metadata(), delete_type, opt_last_logged_opid);
+ Status s = DeleteTabletData(replica->tablet_metadata(), delete_type, opt_last_logged_opid);
if (PREDICT_FALSE(!s.ok())) {
s = s.CloneAndPrepend(Substitute("Unable to delete on-disk data from tablet $0",
tablet_id));
LOG(WARNING) << s.ToString();
- tablet_peer->SetFailed(s);
+ replica->SetFailed(s);
return s;
}
- tablet_peer->StatusMessage("Deleted tablet blocks from disk");
+ replica->StatusMessage("Deleted tablet blocks from disk");
// We only remove DELETED tablets from the tablet map.
if (delete_type == TABLET_DATA_DELETED) {
@@ -713,8 +714,8 @@ void TSTabletManager::OpenTablet(const scoped_refptr<TabletMetadata>& meta,
TRACE_EVENT1("tserver", "TSTabletManager::OpenTablet",
"tablet_id", tablet_id);
- scoped_refptr<TabletPeer> tablet_peer;
- CHECK(LookupTablet(tablet_id, &tablet_peer))
+ scoped_refptr<TabletReplica> replica;
+ CHECK(LookupTablet(tablet_id, &replica))
<< "Tablet not registered prior to OpenTabletAsync call: " << tablet_id;
shared_ptr<Tablet> tablet;
@@ -732,52 +733,52 @@ void TSTabletManager::OpenTablet(const scoped_refptr<TabletMetadata>& meta,
ADOPT_TRACE(nullptr);
// TODO: handle crash mid-creation of tablet? do we ever end up with a
// partially created tablet here?
- tablet_peer->SetBootstrapping();
+ replica->SetBootstrapping();
s = BootstrapTablet(meta,
scoped_refptr<server::Clock>(server_->clock()),
server_->mem_tracker(),
server_->result_tracker(),
metric_registry_,
- implicit_cast<TabletStatusListener*>(tablet_peer.get()),
+ implicit_cast<TabletStatusListener*>(replica.get()),
&tablet,
&log,
- tablet_peer->log_anchor_registry(),
+ replica->log_anchor_registry(),
&bootstrap_info);
if (!s.ok()) {
LOG(ERROR) << LogPrefix(tablet_id) << "Tablet failed to bootstrap: "
<< s.ToString();
- tablet_peer->SetFailed(s);
+ replica->SetFailed(s);
return;
}
}
MonoTime start(MonoTime::Now());
LOG_TIMING_PREFIX(INFO, LogPrefix(tablet_id), "starting tablet") {
- TRACE("Initializing tablet peer");
- s = tablet_peer->Init(tablet,
- scoped_refptr<server::Clock>(server_->clock()),
- server_->messenger(),
- server_->result_tracker(),
- log,
- tablet->GetMetricEntity());
+ TRACE("Initializing tablet replica");
+ s = replica->Init(tablet,
+ scoped_refptr<server::Clock>(server_->clock()),
+ server_->messenger(),
+ server_->result_tracker(),
+ log,
+ tablet->GetMetricEntity());
if (!s.ok()) {
LOG(ERROR) << LogPrefix(tablet_id) << "Tablet failed to init: "
<< s.ToString();
- tablet_peer->SetFailed(s);
+ replica->SetFailed(s);
return;
}
- TRACE("Starting tablet peer");
- s = tablet_peer->Start(bootstrap_info);
+ TRACE("Starting tablet replica");
+ s = replica->Start(bootstrap_info);
if (!s.ok()) {
LOG(ERROR) << LogPrefix(tablet_id) << "Tablet failed to start: "
<< s.ToString();
- tablet_peer->SetFailed(s);
+ replica->SetFailed(s);
return;
}
- tablet_peer->RegisterMaintenanceOps(server_->maintenance_manager());
+ replica->RegisterMaintenanceOps(server_->maintenance_manager());
}
int elapsed_ms = (MonoTime::Now() - start).ToMilliseconds();
@@ -821,14 +822,14 @@ void TSTabletManager::Shutdown() {
// Shut down the bootstrap pool, so no new tablets are registered after this point.
open_tablet_pool_->Shutdown();
- // Take a snapshot of the peers list -- that way we don't have to hold
+ // Take a snapshot of the replicas list -- that way we don't have to hold
// on to the lock while shutting them down, which might cause a lock
// inversion. (see KUDU-308 for example).
- vector<scoped_refptr<TabletPeer> > peers_to_shutdown;
- GetTabletPeers(&peers_to_shutdown);
+ vector<scoped_refptr<TabletReplica> > replicas_to_shutdown;
+ GetTabletReplicas(&replicas_to_shutdown);
- for (const scoped_refptr<TabletPeer>& peer : peers_to_shutdown) {
- peer->Shutdown();
+ for (const scoped_refptr<TabletReplica>& replica : replicas_to_shutdown) {
+ replica->Shutdown();
}
// Shut down the apply pool.
@@ -838,7 +839,7 @@ void TSTabletManager::Shutdown() {
std::lock_guard<rw_spinlock> l(lock_);
// We don't expect anyone else to be modifying the map after we start the
// shut down process.
- CHECK_EQ(tablet_map_.size(), peers_to_shutdown.size())
+ CHECK_EQ(tablet_map_.size(), replicas_to_shutdown.size())
<< "Map contents changed during shutdown!";
tablet_map_.clear();
@@ -847,44 +848,44 @@ void TSTabletManager::Shutdown() {
}
void TSTabletManager::RegisterTablet(const std::string& tablet_id,
- const scoped_refptr<TabletPeer>& tablet_peer,
- RegisterTabletPeerMode mode) {
+ const scoped_refptr<TabletReplica>& replica,
+ RegisterTabletReplicaMode mode) {
std::lock_guard<rw_spinlock> lock(lock_);
- // If we are replacing a tablet peer, we delete the existing one first.
- if (mode == REPLACEMENT_PEER && tablet_map_.erase(tablet_id) != 1) {
- LOG(FATAL) << "Unable to remove previous tablet peer " << tablet_id << ": not registered!";
+ // If we are replacing a tablet replica, we delete the existing one first.
+ if (mode == REPLACEMENT_REPLICA && tablet_map_.erase(tablet_id) != 1) {
+ LOG(FATAL) << "Unable to remove previous tablet replica " << tablet_id << ": not registered!";
}
- if (!InsertIfNotPresent(&tablet_map_, tablet_id, tablet_peer)) {
- LOG(FATAL) << "Unable to register tablet peer " << tablet_id << ": already registered!";
+ if (!InsertIfNotPresent(&tablet_map_, tablet_id, replica)) {
+ LOG(FATAL) << "Unable to register tablet replica " << tablet_id << ": already registered!";
}
- TabletDataState data_state = tablet_peer->tablet_metadata()->tablet_data_state();
+ TabletDataState data_state = replica->tablet_metadata()->tablet_data_state();
LOG(INFO) << LogPrefix(tablet_id) << Substitute("Registered tablet (data state: $0)",
TabletDataState_Name(data_state));
}
bool TSTabletManager::LookupTablet(const string& tablet_id,
- scoped_refptr<TabletPeer>* tablet_peer) const {
+ scoped_refptr<TabletReplica>* replica) const {
shared_lock<rw_spinlock> l(lock_);
- return LookupTabletUnlocked(tablet_id, tablet_peer);
+ return LookupTabletUnlocked(tablet_id, replica);
}
bool TSTabletManager::LookupTabletUnlocked(const string& tablet_id,
- scoped_refptr<TabletPeer>* tablet_peer) const {
- const scoped_refptr<TabletPeer>* found = FindOrNull(tablet_map_, tablet_id);
+ scoped_refptr<TabletReplica>* replica) const {
+ const scoped_refptr<TabletReplica>* found = FindOrNull(tablet_map_, tablet_id);
if (!found) {
return false;
}
- *tablet_peer = *found;
+ *replica = *found;
return true;
}
-Status TSTabletManager::GetTabletPeer(const string& tablet_id,
- scoped_refptr<tablet::TabletPeer>* tablet_peer) const {
- if (!LookupTablet(tablet_id, tablet_peer)) {
+Status TSTabletManager::GetTabletReplica(const string& tablet_id,
+ scoped_refptr<tablet::TabletReplica>* replica) const {
+ if (!LookupTablet(tablet_id, replica)) {
return Status::NotFound("Tablet not found", tablet_id);
}
- TabletDataState data_state = (*tablet_peer)->tablet_metadata()->tablet_data_state();
+ TabletDataState data_state = (*replica)->tablet_metadata()->tablet_data_state();
if (data_state != TABLET_DATA_READY) {
return Status::IllegalState("Tablet data state not TABLET_DATA_READY: " +
TabletDataState_Name(data_state),
@@ -897,9 +898,9 @@ const NodeInstancePB& TSTabletManager::NodeInstance() const {
return server_->instance_pb();
}
-void TSTabletManager::GetTabletPeers(vector<scoped_refptr<TabletPeer> >* tablet_peers) const {
+void TSTabletManager::GetTabletReplicas(vector<scoped_refptr<TabletReplica> >* replicas) const {
shared_lock<rw_spinlock> l(lock_);
- AppendValuesFromMap(tablet_map_, tablet_peers);
+ AppendValuesFromMap(tablet_map_, replicas);
}
void TSTabletManager::MarkTabletDirty(const std::string& tablet_id, const std::string& reason) {
@@ -933,19 +934,19 @@ void TSTabletManager::InitLocalRaftPeerPB() {
}
void TSTabletManager::CreateReportedTabletPB(const string& tablet_id,
- const scoped_refptr<TabletPeer>& tablet_peer,
+ const scoped_refptr<TabletReplica>& replica,
ReportedTabletPB* reported_tablet) const {
reported_tablet->set_tablet_id(tablet_id);
- reported_tablet->set_state(tablet_peer->state());
- reported_tablet->set_tablet_data_state(tablet_peer->tablet_metadata()->tablet_data_state());
- if (tablet_peer->state() == tablet::FAILED) {
+ reported_tablet->set_state(replica->state());
+ reported_tablet->set_tablet_data_state(replica->tablet_metadata()->tablet_data_state());
+ if (replica->state() == tablet::FAILED) {
AppStatusPB* error_status = reported_tablet->mutable_error();
- StatusToPB(tablet_peer->error(), error_status);
+ StatusToPB(replica->error(), error_status);
}
- reported_tablet->set_schema_version(tablet_peer->tablet_metadata()->schema_version());
+ reported_tablet->set_schema_version(replica->tablet_metadata()->schema_version());
- // We cannot get consensus state information unless the TabletPeer is running.
- scoped_refptr<consensus::Consensus> consensus = tablet_peer->shared_consensus();
+ // We cannot get consensus state information unless the TabletReplica is running.
+ scoped_refptr<consensus::Consensus> consensus = replica->shared_consensus();
if (consensus) {
*reported_tablet->mutable_committed_consensus_state() =
consensus->ConsensusState(consensus::CONSENSUS_CONFIG_COMMITTED);
@@ -963,11 +964,11 @@ void TSTabletManager::PopulateIncrementalTabletReport(TabletReportPB* report,
const vector<string>& tablet_ids) const {
shared_lock<rw_spinlock> shared_lock(lock_);
for (const auto& id : tablet_ids) {
- const scoped_refptr<tablet::TabletPeer>* tablet_peer =
+ const scoped_refptr<tablet::TabletReplica>* replica =
FindOrNull(tablet_map_, id);
- if (tablet_peer) {
+ if (replica) {
// Dirty entry, report on it.
- CreateReportedTabletPB(id, *tablet_peer, report->add_updated_tablets());
+ CreateReportedTabletPB(id, *replica, report->add_updated_tablets());
} else {
// Removed.
report->add_removed_tablet_ids(id);
@@ -1007,7 +1008,7 @@ Status TSTabletManager::HandleNonReadyTabletOnStartup(const scoped_refptr<Tablet
// allows us to permanently delete replica tombstones when a table gets
// deleted.
if (data_state == TABLET_DATA_TOMBSTONED) {
- CreateAndRegisterTabletPeer(meta, NEW_PEER);
+ CreateAndRegisterTabletReplica(meta, NEW_REPLICA);
}
return Status::OK();
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/ts_tablet_manager.h
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/ts_tablet_manager.h b/src/kudu/tserver/ts_tablet_manager.h
index 6f437be..f234f56 100644
--- a/src/kudu/tserver/ts_tablet_manager.h
+++ b/src/kudu/tserver/ts_tablet_manager.h
@@ -27,7 +27,7 @@
#include "kudu/gutil/macros.h"
#include "kudu/gutil/ref_counted.h"
-#include "kudu/tserver/tablet_peer_lookup.h"
+#include "kudu/tserver/tablet_replica_lookup.h"
#include "kudu/tserver/tserver_admin.pb.h"
#include "kudu/tserver/tserver.pb.h"
#include "kudu/util/locks.h"
@@ -58,7 +58,7 @@ class ResultTracker;
namespace tablet {
class TabletMetadata;
-class TabletPeer;
+class TabletReplica;
class TabletStatusPB;
class TabletStatusListener;
}
@@ -76,7 +76,7 @@ class TransitionInProgressDeleter;
// TODO: will also be responsible for keeping the local metadata about
// which tablets are hosted on this server persistent on disk, as well
// as re-opening all the tablets at startup, etc.
-class TSTabletManager : public tserver::TabletPeerLookupIf {
+class TSTabletManager : public tserver::TabletReplicaLookupIf {
public:
// Construct the tablet manager.
// 'fs_manager' must remain valid until this object is destructed.
@@ -103,7 +103,7 @@ class TSTabletManager : public tserver::TabletPeerLookupIf {
// Create a new tablet and register it with the tablet manager. The new tablet
// is persisted on disk and opened before this method returns.
//
- // If tablet_peer is non-NULL, the newly created tablet will be returned.
+ // If 'replica' is non-NULL, the newly created tablet will be returned.
//
// If another tablet already exists with this ID, logs a DFATAL
// and returns a bad Status.
@@ -114,7 +114,7 @@ class TSTabletManager : public tserver::TabletPeerLookupIf {
const Schema& schema,
const PartitionSchema& partition_schema,
consensus::RaftConfigPB config,
- scoped_refptr<tablet::TabletPeer>* tablet_peer);
+ scoped_refptr<tablet::TabletReplica>* replica);
// Delete the specified tablet.
// 'delete_type' must be one of TABLET_DATA_DELETED or TABLET_DATA_TOMBSTONED
@@ -129,18 +129,18 @@ class TSTabletManager : public tserver::TabletPeerLookupIf {
const boost::optional<int64_t>& cas_config_opid_index_less_or_equal,
boost::optional<TabletServerErrorPB::Code>* error_code);
- // Lookup the given tablet peer by its ID.
+ // Lookup the given tablet replica by its ID.
// Returns true if the tablet is found successfully.
bool LookupTablet(const std::string& tablet_id,
- scoped_refptr<tablet::TabletPeer>* tablet_peer) const;
+ scoped_refptr<tablet::TabletReplica>* replica) const;
// Same as LookupTablet but doesn't acquired the shared lock.
bool LookupTabletUnlocked(const std::string& tablet_id,
- scoped_refptr<tablet::TabletPeer>* tablet_peer) const;
+ scoped_refptr<tablet::TabletReplica>* replica) const;
- virtual Status GetTabletPeer(const std::string& tablet_id,
- scoped_refptr<tablet::TabletPeer>* tablet_peer) const
- override;
+ virtual Status GetTabletReplica(const std::string& tablet_id,
+ scoped_refptr<tablet::TabletReplica>* replica) const
+ override;
virtual const NodeInstancePB& NodeInstance() const override;
@@ -165,7 +165,7 @@ class TSTabletManager : public tserver::TabletPeerLookupIf {
const std::vector<std::string>& tablet_ids) const;
// Get all of the tablets currently hosted on this server.
- void GetTabletPeers(std::vector<scoped_refptr<tablet::TabletPeer> >* tablet_peers) const;
+ void GetTabletReplicas(std::vector<scoped_refptr<tablet::TabletReplica> >* replicas) const;
// Marks tablet with 'tablet_id' as dirty so that it'll be included in the
// next round of master heartbeats.
@@ -187,10 +187,10 @@ class TSTabletManager : public tserver::TabletPeerLookupIf {
private:
FRIEND_TEST(TsTabletManagerTest, TestPersistBlocks);
- // Flag specified when registering a TabletPeer.
- enum RegisterTabletPeerMode {
- NEW_PEER,
- REPLACEMENT_PEER
+ // Flag specified when registering a TabletReplica.
+ enum RegisterTabletReplicaMode {
+ NEW_REPLICA,
+ REPLACEMENT_REPLICA
};
// Standard log prefix, given a tablet id.
@@ -222,7 +222,7 @@ class TSTabletManager : public tserver::TabletPeerLookupIf {
// This method does not return anything as it can be run asynchronously.
// Upon completion of this method the tablet should be initialized and running.
// If something wrong happened on bootstrap/initialization the relevant error
- // will be set on TabletPeer along with the state set to FAILED.
+ // will be set on TabletReplica along with the state set to FAILED.
//
// The tablet must be registered and an entry corresponding to this tablet
// must be put into the transition_in_progress_ map before calling this
@@ -234,30 +234,30 @@ class TSTabletManager : public tserver::TabletPeerLookupIf {
// Open a tablet whose metadata has already been loaded.
void BootstrapAndInitTablet(const scoped_refptr<tablet::TabletMetadata>& meta,
- scoped_refptr<tablet::TabletPeer>* peer);
+ scoped_refptr<tablet::TabletReplica>* replica);
// Add the tablet to the tablet map.
// 'mode' specifies whether to expect an existing tablet to exist in the map.
- // If mode == NEW_PEER but a tablet with the same name is already registered,
- // or if mode == REPLACEMENT_PEER but a tablet with the same name is not
+ // If mode == NEW_REPLICA but a tablet with the same name is already registered,
+ // or if mode == REPLACEMENT_REPLICA but a tablet with the same name is not
// registered, a FATAL message is logged, causing a process crash.
// Calls to this method are expected to be externally synchronized, typically
// using the transition_in_progress_ map.
void RegisterTablet(const std::string& tablet_id,
- const scoped_refptr<tablet::TabletPeer>& tablet_peer,
- RegisterTabletPeerMode mode);
+ const scoped_refptr<tablet::TabletReplica>& replica,
+ RegisterTabletReplicaMode mode);
- // Create and register a new TabletPeer, given tablet metadata.
+ // Create and register a new TabletReplica, given tablet metadata.
// Calls RegisterTablet() with the given 'mode' parameter after constructing
// the TablerPeer object. See RegisterTablet() for details about the
// semantics of 'mode' and the locking requirements.
- scoped_refptr<tablet::TabletPeer> CreateAndRegisterTabletPeer(
+ scoped_refptr<tablet::TabletReplica> CreateAndRegisterTabletReplica(
const scoped_refptr<tablet::TabletMetadata>& meta,
- RegisterTabletPeerMode mode);
+ RegisterTabletReplicaMode mode);
// Helper to generate the report for a single tablet.
void CreateReportedTabletPB(const std::string& tablet_id,
- const scoped_refptr<tablet::TabletPeer>& tablet_peer,
+ const scoped_refptr<tablet::TabletReplica>& replica,
master::ReportedTabletPB* reported_tablet) const;
// Handle the case on startup where we find a tablet that is not in
@@ -287,7 +287,7 @@ class TSTabletManager : public tserver::TabletPeerLookupIf {
consensus::RaftPeerPB local_peer_pb_;
- typedef std::unordered_map<std::string, scoped_refptr<tablet::TabletPeer> > TabletMap;
+ typedef std::unordered_map<std::string, scoped_refptr<tablet::TabletReplica> > TabletMap;
// Lock protecting tablet_map_, dirty_tablets_, state_,
// transition_in_progress_, and perm_deleted_tablet_ids_.
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/tserver-path-handlers.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tserver-path-handlers.cc b/src/kudu/tserver/tserver-path-handlers.cc
index 9dc4b53..f12e4b9 100644
--- a/src/kudu/tserver/tserver-path-handlers.cc
+++ b/src/kudu/tserver/tserver-path-handlers.cc
@@ -34,7 +34,7 @@
#include "kudu/server/webui_util.h"
#include "kudu/tablet/tablet.pb.h"
#include "kudu/tablet/tablet_bootstrap.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tserver/scanners.h"
#include "kudu/tserver/tablet_server.h"
#include "kudu/tserver/ts_tablet_manager.h"
@@ -51,7 +51,7 @@ using kudu::MaintenanceManagerStatusPB;
using kudu::MaintenanceManagerStatusPB_CompletedOpPB;
using kudu::MaintenanceManagerStatusPB_MaintenanceOpPB;
using kudu::tablet::Tablet;
-using kudu::tablet::TabletPeer;
+using kudu::tablet::TabletReplica;
using kudu::tablet::TabletStatusPB;
using kudu::tablet::Transaction;
using std::endl;
@@ -110,8 +110,8 @@ void TabletServerPathHandlers::HandleTransactionsPage(const Webserver::WebReques
std::ostringstream* output) {
bool as_text = ContainsKey(req.parsed_args, "raw");
- vector<scoped_refptr<TabletPeer> > peers;
- tserver_->tablet_manager()->GetTabletPeers(&peers);
+ vector<scoped_refptr<TabletReplica> > replicas;
+ tserver_->tablet_manager()->GetTabletReplicas(&replicas);
string arg = FindWithDefault(req.parsed_args, "include_traces", "false");
Transaction::TraceType trace_type = ParseLeadingBoolValue(
@@ -125,14 +125,14 @@ void TabletServerPathHandlers::HandleTransactionsPage(const Webserver::WebReques
"Total time in-flight</th><th>Description</th></tr>\n";
}
- for (const scoped_refptr<TabletPeer>& peer : peers) {
+ for (const scoped_refptr<TabletReplica>& replica : replicas) {
vector<TransactionStatusPB> inflight;
- if (peer->tablet() == nullptr) {
+ if (replica->tablet() == nullptr) {
continue;
}
- peer->GetInFlightTransactions(trace_type, &inflight);
+ replica->GetInFlightTransactions(trace_type, &inflight);
for (const TransactionStatusPB& inflight_tx : inflight) {
string total_time_str = Substitute("$0 us.", inflight_tx.running_for_micros());
string description;
@@ -146,13 +146,13 @@ void TabletServerPathHandlers::HandleTransactionsPage(const Webserver::WebReques
if (!as_text) {
(*output) << Substitute(
"<tr><th>$0</th><th>$1</th><th>$2</th><th>$3</th><th>$4</th></tr>\n",
- EscapeForHtmlToString(peer->tablet_id()),
+ EscapeForHtmlToString(replica->tablet_id()),
EscapeForHtmlToString(SecureShortDebugString(inflight_tx.op_id())),
OperationType_Name(inflight_tx.tx_type()),
total_time_str,
EscapeForHtmlToString(description));
} else {
- (*output) << "Tablet: " << peer->tablet_id() << endl;
+ (*output) << "Tablet: " << replica->tablet_id() << endl;
(*output) << "Op ID: " << SecureShortDebugString(inflight_tx.op_id()) << endl;
(*output) << "Type: " << OperationType_Name(inflight_tx.tx_type()) << endl;
(*output) << "Running: " << total_time_str;
@@ -178,32 +178,32 @@ string TabletLink(const string& id) {
void TabletServerPathHandlers::HandleTabletsPage(const Webserver::WebRequest& req,
std::ostringstream *output) {
- vector<scoped_refptr<TabletPeer>> peers;
- tserver_->tablet_manager()->GetTabletPeers(&peers);
+ vector<scoped_refptr<TabletReplica>> replicas;
+ tserver_->tablet_manager()->GetTabletReplicas(&replicas);
// Sort by (table_name, tablet_id) tuples.
- std::sort(peers.begin(), peers.end(),
- [](const scoped_refptr<TabletPeer>& peer_a,
- const scoped_refptr<TabletPeer>& peer_b) {
- return std::make_pair(peer_a->tablet_metadata()->table_name(), peer_a->tablet_id()) <
- std::make_pair(peer_b->tablet_metadata()->table_name(), peer_b->tablet_id());
+ std::sort(replicas.begin(), replicas.end(),
+ [](const scoped_refptr<TabletReplica>& rep_a,
+ const scoped_refptr<TabletReplica>& rep_b) {
+ return std::make_pair(rep_a->tablet_metadata()->table_name(), rep_a->tablet_id()) <
+ std::make_pair(rep_b->tablet_metadata()->table_name(), rep_b->tablet_id());
});
auto generate_table = [this](const string& header,
- const vector<scoped_refptr<TabletPeer>>& peers,
+ const vector<scoped_refptr<TabletReplica>>& replicas,
ostream* output) {
*output << "<h3>" << header << "</h3>\n";
*output << "<table class='table table-striped'>\n";
*output << " <tr><th>Table name</th><th>Tablet ID</th>"
"<th>Partition</th>"
"<th>State</th><th>On-disk size</th><th>RaftConfig</th><th>Last status</th></tr>\n";
- for (const scoped_refptr<TabletPeer>& peer : peers) {
+ for (const scoped_refptr<TabletReplica>& replica : replicas) {
TabletStatusPB status;
- peer->GetTabletStatusPB(&status);
+ replica->GetTabletStatusPB(&status);
string id = status.tablet_id();
string table_name = status.table_name();
string tablet_id_or_link;
- if (peer->tablet() != nullptr) {
+ if (replica->tablet() != nullptr) {
tablet_id_or_link = TabletLink(id);
} else {
tablet_id_or_link = EscapeForHtmlToString(id);
@@ -212,13 +212,13 @@ void TabletServerPathHandlers::HandleTabletsPage(const Webserver::WebRequest& re
if (status.has_estimated_on_disk_size()) {
n_bytes = HumanReadableNumBytes::ToString(status.estimated_on_disk_size());
}
- string partition = peer->tablet_metadata()
- ->partition_schema()
- .PartitionDebugString(peer->tablet_metadata()->partition(),
- peer->tablet_metadata()->schema());
+ string partition = replica->tablet_metadata()
+ ->partition_schema()
+ .PartitionDebugString(replica->tablet_metadata()->partition(),
+ replica->tablet_metadata()->schema());
// TODO(unknown): would be nice to include some other stuff like memory usage
- scoped_refptr<consensus::Consensus> consensus = peer->shared_consensus();
+ scoped_refptr<consensus::Consensus> consensus = replica->shared_consensus();
(*output) << Substitute(
// Table name, tablet id, partition
"<tr><td>$0</td><td>$1</td><td>$2</td>"
@@ -227,7 +227,7 @@ void TabletServerPathHandlers::HandleTabletsPage(const Webserver::WebRequest& re
EscapeForHtmlToString(table_name), // $0
tablet_id_or_link, // $1
EscapeForHtmlToString(partition), // $2
- EscapeForHtmlToString(peer->HumanReadableState()), n_bytes, // $3, $4
+ EscapeForHtmlToString(replica->HumanReadableState()), n_bytes, // $3, $4
consensus ? ConsensusStatePBToHtml(consensus->
ConsensusState(CONSENSUS_CONFIG_COMMITTED))
: "", // $5
@@ -236,21 +236,21 @@ void TabletServerPathHandlers::HandleTabletsPage(const Webserver::WebRequest& re
*output << "</table>\n";
};
- vector<scoped_refptr<TabletPeer>> live_peers;
- vector<scoped_refptr<TabletPeer>> tombstoned_peers;
- for (const scoped_refptr<TabletPeer>& peer : peers) {
- if (peer->HumanReadableState() != "TABLET_DATA_TOMBSTONED") {
- live_peers.push_back(peer);
+ vector<scoped_refptr<TabletReplica>> live_replicas;
+ vector<scoped_refptr<TabletReplica>> tombstoned_replicas;
+ for (const scoped_refptr<TabletReplica>& replica : replicas) {
+ if (replica->HumanReadableState() != "TABLET_DATA_TOMBSTONED") {
+ live_replicas.push_back(replica);
} else {
- tombstoned_peers.push_back(peer);
+ tombstoned_replicas.push_back(replica);
}
}
- if (!live_peers.empty()) {
- generate_table("Live Tablets", live_peers, output);
+ if (!live_replicas.empty()) {
+ generate_table("Live Tablets", live_replicas, output);
}
- if (!tombstoned_peers.empty()) {
- generate_table("Tombstoned Tablets", tombstoned_peers, output);
+ if (!tombstoned_replicas.empty()) {
+ generate_table("Tombstoned Tablets", tombstoned_replicas, output);
*output << "<p><small>Tombstoned tablets are tablets that previously "
"stored a replica on this server.</small></p>";
}
@@ -304,19 +304,19 @@ bool GetTabletID(const Webserver::WebRequest& req, string* id, std::ostringstrea
return true;
}
-bool GetTabletPeer(TabletServer* tserver, const Webserver::WebRequest& req,
- scoped_refptr<TabletPeer>* peer, const string& tablet_id,
- std::ostringstream* out) {
- if (!tserver->tablet_manager()->LookupTablet(tablet_id, peer)) {
+bool GetTabletReplica(TabletServer* tserver, const Webserver::WebRequest& req,
+ scoped_refptr<TabletReplica>* replica, const string& tablet_id,
+ std::ostringstream* out) {
+ if (!tserver->tablet_manager()->LookupTablet(tablet_id, replica)) {
(*out) << "Tablet " << EscapeForHtmlToString(tablet_id) << " not found";
return false;
}
return true;
}
-bool TabletBootstrapping(const scoped_refptr<TabletPeer>& peer, const string& tablet_id,
+bool TabletBootstrapping(const scoped_refptr<TabletReplica>& replica, const string& tablet_id,
std::ostringstream* out) {
- if (peer->state() == tablet::BOOTSTRAPPING) {
+ if (replica->state() == tablet::BOOTSTRAPPING) {
(*out) << "Tablet " << EscapeForHtmlToString(tablet_id) << " is still bootstrapping";
return false;
}
@@ -327,11 +327,11 @@ bool TabletBootstrapping(const scoped_refptr<TabletPeer>& peer, const string& ta
// tablet is found, and is in a non-bootstrapping state.
bool LoadTablet(TabletServer* tserver,
const Webserver::WebRequest& req,
- string* tablet_id, scoped_refptr<TabletPeer>* peer,
+ string* tablet_id, scoped_refptr<TabletReplica>* replica,
std::ostringstream* out) {
if (!GetTabletID(req, tablet_id, out)) return false;
- if (!GetTabletPeer(tserver, req, peer, *tablet_id, out)) return false;
- if (!TabletBootstrapping(*peer, *tablet_id, out)) return false;
+ if (!GetTabletReplica(tserver, req, replica, *tablet_id, out)) return false;
+ if (!TabletBootstrapping(*replica, *tablet_id, out)) return false;
return true;
}
@@ -340,24 +340,24 @@ bool LoadTablet(TabletServer* tserver,
void TabletServerPathHandlers::HandleTabletPage(const Webserver::WebRequest& req,
std::ostringstream *output) {
string tablet_id;
- scoped_refptr<TabletPeer> peer;
- if (!LoadTablet(tserver_, req, &tablet_id, &peer, output)) return;
+ scoped_refptr<TabletReplica> replica;
+ if (!LoadTablet(tserver_, req, &tablet_id, &replica, output)) return;
- string table_name = peer->tablet_metadata()->table_name();
+ string table_name = replica->tablet_metadata()->table_name();
RaftPeerPB::Role role = RaftPeerPB::UNKNOWN_ROLE;
- auto consensus = peer->consensus();
+ auto consensus = replica->consensus();
if (consensus) {
role = consensus->role();
}
*output << "<h1>Tablet " << EscapeForHtmlToString(tablet_id)
- << " (" << peer->HumanReadableState()
+ << " (" << replica->HumanReadableState()
<< "/" << RaftPeerPB::Role_Name(role) << ")</h1>\n";
*output << "<h3>Table " << EscapeForHtmlToString(table_name) << "</h3>";
// Output schema in tabular format.
*output << "<h2>Schema</h2>\n";
- const Schema& schema = peer->tablet_metadata()->schema();
+ const Schema& schema = replica->tablet_metadata()->schema();
HtmlOutputSchemaTable(schema, output);
*output << "<h2>Other Tablet Info Pages</h2>" << endl;
@@ -390,9 +390,9 @@ void TabletServerPathHandlers::HandleTabletPage(const Webserver::WebRequest& req
void TabletServerPathHandlers::HandleTabletSVGPage(const Webserver::WebRequest& req,
std::ostringstream* output) {
string id;
- scoped_refptr<TabletPeer> peer;
- if (!LoadTablet(tserver_, req, &id, &peer, output)) return;
- shared_ptr<Tablet> tablet = peer->shared_tablet();
+ scoped_refptr<TabletReplica> replica;
+ if (!LoadTablet(tserver_, req, &id, &replica, output)) return;
+ shared_ptr<Tablet> tablet = replica->shared_tablet();
if (!tablet) {
*output << "Tablet " << EscapeForHtmlToString(id) << " not running";
return;
@@ -407,22 +407,22 @@ void TabletServerPathHandlers::HandleTabletSVGPage(const Webserver::WebRequest&
void TabletServerPathHandlers::HandleLogAnchorsPage(const Webserver::WebRequest& req,
std::ostringstream* output) {
string tablet_id;
- scoped_refptr<TabletPeer> peer;
- if (!LoadTablet(tserver_, req, &tablet_id, &peer, output)) return;
+ scoped_refptr<TabletReplica> replica;
+ if (!LoadTablet(tserver_, req, &tablet_id, &replica, output)) return;
*output << "<h1>Log Anchors for Tablet " << EscapeForHtmlToString(tablet_id) << "</h1>"
<< std::endl;
- string dump = peer->log_anchor_registry()->DumpAnchorInfo();
+ string dump = replica->log_anchor_registry()->DumpAnchorInfo();
*output << "<pre>" << EscapeForHtmlToString(dump) << "</pre>" << std::endl;
}
void TabletServerPathHandlers::HandleConsensusStatusPage(const Webserver::WebRequest& req,
std::ostringstream* output) {
string id;
- scoped_refptr<TabletPeer> peer;
- if (!LoadTablet(tserver_, req, &id, &peer, output)) return;
- scoped_refptr<consensus::Consensus> consensus = peer->shared_consensus();
+ scoped_refptr<TabletReplica> replica;
+ if (!LoadTablet(tserver_, req, &id, &replica, output)) return;
+ scoped_refptr<consensus::Consensus> consensus = replica->shared_consensus();
if (!consensus) {
*output << "Tablet " << EscapeForHtmlToString(id) << " not running";
return;
@@ -471,8 +471,8 @@ string TabletServerPathHandlers::ScannerToHtml(const Scanner& scanner) const {
scanner.GetIteratorStats(&stats);
CHECK_EQ(stats.size(), projection->num_columns());
html << Substitute("<td>$0</td>", IteratorStatsToHtml(*projection, stats));
- scoped_refptr<TabletPeer> tablet_peer;
- if (!tserver_->tablet_manager()->LookupTablet(scanner.tablet_id(), &tablet_peer)) {
+ scoped_refptr<TabletReplica> tablet_replica;
+ if (!tserver_->tablet_manager()->LookupTablet(scanner.tablet_id(), &tablet_replica)) {
html << Substitute("<td colspan=\"2\"><b>Tablet $0 is no longer valid.</b></td></tr>\n",
scanner.tablet_id());
} else {
[2/5] kudu git commit: Rename TabletPeer to TabletReplica
Posted by mp...@apache.org.
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/transactions/write_transaction.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/transactions/write_transaction.cc b/src/kudu/tablet/transactions/write_transaction.cc
index 592635e..acec316 100644
--- a/src/kudu/tablet/transactions/write_transaction.cc
+++ b/src/kudu/tablet/transactions/write_transaction.cc
@@ -29,7 +29,7 @@
#include "kudu/server/hybrid_clock.h"
#include "kudu/tablet/row_op.h"
#include "kudu/tablet/tablet.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tablet/tablet_metrics.h"
#include "kudu/tserver/tserver.pb.h"
#include "kudu/util/debug/trace_event.h"
@@ -86,7 +86,7 @@ Status WriteTransaction::Prepare() {
return s;
}
- Tablet* tablet = state()->tablet_peer()->tablet();
+ Tablet* tablet = state()->tablet_replica()->tablet();
Status s = tablet->DecodeWriteOperations(&client_schema, state());
if (!s.ok()) {
@@ -112,8 +112,8 @@ Status WriteTransaction::Start() {
DCHECK(!state_->has_timestamp());
DCHECK(state_->consensus_round()->replicate_msg()->has_timestamp());
state_->set_timestamp(Timestamp(state_->consensus_round()->replicate_msg()->timestamp()));
- state_->tablet_peer()->tablet()->StartTransaction(state_.get());
- TRACE("Timestamp: $0", state_->tablet_peer()->clock()->Stringify(state_->timestamp()));
+ state_->tablet_replica()->tablet()->StartTransaction(state_.get());
+ TRACE("Timestamp: $0", state_->tablet_replica()->clock()->Stringify(state_->timestamp()));
return Status::OK();
}
@@ -130,7 +130,7 @@ Status WriteTransaction::Apply(gscoped_ptr<CommitMsg>* commit_msg) {
SleepFor(MonoDelta::FromMilliseconds(FLAGS_tablet_inject_latency_on_apply_write_txn_ms));
}
- Tablet* tablet = state()->tablet_peer()->tablet();
+ Tablet* tablet = state()->tablet_replica()->tablet();
tablet->ApplyRowOperations(state());
@@ -171,7 +171,7 @@ void WriteTransaction::Finish(TransactionResult result) {
TRACE("FINISH: updating metrics");
- TabletMetrics* metrics = state_->tablet_peer()->tablet()->metrics();
+ TabletMetrics* metrics = state_->tablet_replica()->tablet()->metrics();
if (metrics) {
// TODO: should we change this so it's actually incremented by the
// Tablet code itself instead of this wrapper code?
@@ -210,11 +210,11 @@ string WriteTransaction::ToString() const {
DriverType_Name(type()), abs_time_formatted, state_->ToString());
}
-WriteTransactionState::WriteTransactionState(TabletPeer* tablet_peer,
+WriteTransactionState::WriteTransactionState(TabletReplica* tablet_replica,
const tserver::WriteRequestPB *request,
const rpc::RequestIdPB* request_id,
tserver::WriteResponsePB *response)
- : TransactionState(tablet_peer),
+ : TransactionState(tablet_replica),
request_(DCHECK_NOTNULL(request)),
response_(response),
mvcc_tx_(nullptr),
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/transactions/write_transaction.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/transactions/write_transaction.h b/src/kudu/tablet/transactions/write_transaction.h
index da03433..f8ea48d 100644
--- a/src/kudu/tablet/transactions/write_transaction.h
+++ b/src/kudu/tablet/transactions/write_transaction.h
@@ -73,7 +73,7 @@ struct TabletComponents;
// NOTE: this class isn't thread safe.
class WriteTransactionState : public TransactionState {
public:
- WriteTransactionState(TabletPeer* tablet_peer,
+ WriteTransactionState(TabletReplica* tablet_replica,
const tserver::WriteRequestPB *request,
const rpc::RequestIdPB* request_id,
tserver::WriteResponsePB *response = NULL);
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tools/kudu-tool-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/kudu-tool-test.cc b/src/kudu/tools/kudu-tool-test.cc
index d996e1e..1ffd090 100644
--- a/src/kudu/tools/kudu-tool-test.cc
+++ b/src/kudu/tools/kudu-tool-test.cc
@@ -57,7 +57,7 @@
#include "kudu/tablet/local_tablet_writer.h"
#include "kudu/tablet/tablet-harness.h"
#include "kudu/tablet/tablet_metadata.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tablet/tablet.h"
#include "kudu/tools/tool_action_common.h"
#include "kudu/tools/tool_test_util.h"
@@ -107,7 +107,7 @@ using tablet::Tablet;
using tablet::TabletDataState;
using tablet::TabletHarness;
using tablet::TabletMetadata;
-using tablet::TabletPeer;
+using tablet::TabletReplica;
using tablet::TabletSuperBlockPB;
using tserver::DeleteTabletRequestPB;
using tserver::DeleteTabletResponsePB;
@@ -1250,12 +1250,12 @@ TEST_F(ToolTest, TestLocalReplicaDelete) {
// is reduced at all.
string tablet_id;
{
- vector<scoped_refptr<TabletPeer>> tablet_peers;
- ts->server()->tablet_manager()->GetTabletPeers(&tablet_peers);
- ASSERT_EQ(1, tablet_peers.size());
- Tablet* tablet = tablet_peers[0]->tablet();
+ vector<scoped_refptr<TabletReplica>> tablet_replicas;
+ ts->server()->tablet_manager()->GetTabletReplicas(&tablet_replicas);
+ ASSERT_EQ(1, tablet_replicas.size());
+ Tablet* tablet = tablet_replicas[0]->tablet();
ASSERT_OK(tablet->Flush());
- tablet_id = tablet_peers[0]->tablet_id();
+ tablet_id = tablet_replicas[0]->tablet_id();
}
const string& tserver_dir = ts->options()->fs_opts.wal_path;
// Using the delete tool with tablet server running fails.
@@ -1297,9 +1297,9 @@ TEST_F(ToolTest, TestLocalReplicaDelete) {
// we can expect the tablet server to have nothing after it comes up.
ASSERT_OK(ts->Start());
ASSERT_OK(ts->WaitStarted());
- vector<scoped_refptr<TabletPeer>> tablet_peers;
- ts->server()->tablet_manager()->GetTabletPeers(&tablet_peers);
- ASSERT_EQ(0, tablet_peers.size());
+ vector<scoped_refptr<TabletReplica>> tablet_replicas;
+ ts->server()->tablet_manager()->GetTabletReplicas(&tablet_replicas);
+ ASSERT_EQ(0, tablet_replicas.size());
}
// Test 'kudu local_replica delete' tool for tombstoning the tablet.
@@ -1330,12 +1330,12 @@ TEST_F(ToolTest, TestLocalReplicaTombstoneDelete) {
last_logged_opid.Clear();
string tablet_id;
{
- vector<scoped_refptr<TabletPeer>> tablet_peers;
- ts->server()->tablet_manager()->GetTabletPeers(&tablet_peers);
- ASSERT_EQ(1, tablet_peers.size());
- tablet_id = tablet_peers[0]->tablet_id();
- tablet_peers[0]->log()->GetLatestEntryOpId(&last_logged_opid);
- Tablet* tablet = tablet_peers[0]->tablet();
+ vector<scoped_refptr<TabletReplica>> tablet_replicas;
+ ts->server()->tablet_manager()->GetTabletReplicas(&tablet_replicas);
+ ASSERT_EQ(1, tablet_replicas.size());
+ tablet_id = tablet_replicas[0]->tablet_id();
+ tablet_replicas[0]->log()->GetLatestEntryOpId(&last_logged_opid);
+ Tablet* tablet = tablet_replicas[0]->tablet();
ASSERT_OK(tablet->Flush());
}
const string& tserver_dir = ts->options()->fs_opts.wal_path;
@@ -1362,13 +1362,13 @@ TEST_F(ToolTest, TestLocalReplicaTombstoneDelete) {
ASSERT_OK(ts->Start());
ASSERT_OK(ts->WaitStarted());
{
- vector<scoped_refptr<TabletPeer>> tablet_peers;
- ts->server()->tablet_manager()->GetTabletPeers(&tablet_peers);
- ASSERT_EQ(1, tablet_peers.size());
- ASSERT_EQ(tablet_id, tablet_peers[0]->tablet_id());
+ vector<scoped_refptr<TabletReplica>> tablet_replicas;
+ ts->server()->tablet_manager()->GetTabletReplicas(&tablet_replicas);
+ ASSERT_EQ(1, tablet_replicas.size());
+ ASSERT_EQ(tablet_id, tablet_replicas[0]->tablet_id());
ASSERT_EQ(TabletDataState::TABLET_DATA_TOMBSTONED,
- tablet_peers[0]->tablet_metadata()->tablet_data_state());
- OpId tombstoned_opid = tablet_peers[0]->tablet_metadata()->tombstone_last_logged_opid();
+ tablet_replicas[0]->tablet_metadata()->tablet_data_state());
+ OpId tombstoned_opid = tablet_replicas[0]->tablet_metadata()->tombstone_last_logged_opid();
ASSERT_TRUE(tombstoned_opid.IsInitialized());
ASSERT_EQ(last_logged_opid.term(), tombstoned_opid.term());
ASSERT_EQ(last_logged_opid.index(), tombstoned_opid.index());
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/scanners-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/scanners-test.cc b/src/kudu/tserver/scanners-test.cc
index 5541bc3..f0b7473 100644
--- a/src/kudu/tserver/scanners-test.cc
+++ b/src/kudu/tserver/scanners-test.cc
@@ -19,7 +19,7 @@
#include <vector>
#include <gtest/gtest.h>
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tserver/scanner_metrics.h"
#include "kudu/tserver/tserver.pb.h"
#include "kudu/util/metrics.h"
@@ -29,20 +29,20 @@ DECLARE_int32(scanner_ttl_ms);
namespace kudu {
-using tablet::TabletPeer;
+using tablet::TabletReplica;
namespace tserver {
using std::vector;
TEST(ScannersTest, TestManager) {
- scoped_refptr<TabletPeer> null_peer(nullptr);
+ scoped_refptr<TabletReplica> null_replica(nullptr);
ScannerManager mgr(nullptr);
// Create two scanners, make sure their ids are different.
SharedScanner s1, s2;
- mgr.NewScanner(null_peer, "", RowFormatFlags::NO_FLAGS, &s1);
- mgr.NewScanner(null_peer, "", RowFormatFlags::NO_FLAGS, &s2);
+ mgr.NewScanner(null_replica, "", RowFormatFlags::NO_FLAGS, &s1);
+ mgr.NewScanner(null_replica, "", RowFormatFlags::NO_FLAGS, &s2);
ASSERT_NE(s1->id(), s2->id());
// Check that they're both registered.
@@ -65,13 +65,13 @@ TEST(ScannersTest, TestManager) {
}
TEST(ScannerTest, TestExpire) {
- scoped_refptr<TabletPeer> null_peer(nullptr);
+ scoped_refptr<TabletReplica> null_replica(nullptr);
FLAGS_scanner_ttl_ms = 100;
MetricRegistry registry;
ScannerManager mgr(METRIC_ENTITY_server.Instantiate(®istry, "test"));
SharedScanner s1, s2;
- mgr.NewScanner(null_peer, "", RowFormatFlags::NO_FLAGS, &s1);
- mgr.NewScanner(null_peer, "", RowFormatFlags::NO_FLAGS, &s2);
+ mgr.NewScanner(null_replica, "", RowFormatFlags::NO_FLAGS, &s1);
+ mgr.NewScanner(null_replica, "", RowFormatFlags::NO_FLAGS, &s2);
SleepFor(MonoDelta::FromMilliseconds(200));
s2->UpdateAccessTime();
mgr.RemoveExpiredScanners();
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/scanners.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/scanners.cc b/src/kudu/tserver/scanners.cc
index ec0f77c..6dd8295 100644
--- a/src/kudu/tserver/scanners.cc
+++ b/src/kudu/tserver/scanners.cc
@@ -49,7 +49,7 @@ using strings::Substitute;
namespace kudu {
-using tablet::TabletPeer;
+using tablet::TabletReplica;
namespace tserver {
@@ -106,7 +106,7 @@ ScannerManager::ScannerMapStripe& ScannerManager::GetStripeByScannerId(const str
return *scanner_maps_[slot];
}
-void ScannerManager::NewScanner(const scoped_refptr<TabletPeer>& tablet_peer,
+void ScannerManager::NewScanner(const scoped_refptr<TabletReplica>& tablet_replica,
const std::string& requestor_string,
uint64 row_format_flags,
SharedScanner* scanner) {
@@ -119,7 +119,7 @@ void ScannerManager::NewScanner(const scoped_refptr<TabletPeer>& tablet_peer,
// verify that the requestor userid does not change mid-scan.
string id = oid_generator_.Next();
scanner->reset(new Scanner(id,
- tablet_peer,
+ tablet_replica,
requestor_string,
metrics_.get(),
row_format_flags));
@@ -192,11 +192,11 @@ void ScannerManager::RemoveExpiredScanners() {
const std::string Scanner::kNullTabletId = "null tablet";
-Scanner::Scanner(string id, const scoped_refptr<TabletPeer>& tablet_peer,
+Scanner::Scanner(string id, const scoped_refptr<TabletReplica>& tablet_replica,
string requestor_string, ScannerMetrics* metrics,
uint64_t row_format_flags)
: id_(std::move(id)),
- tablet_peer_(tablet_peer),
+ tablet_replica_(tablet_replica),
requestor_string_(std::move(requestor_string)),
call_seq_id_(0),
start_time_(MonoTime::Now()),
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/scanners.h
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/scanners.h b/src/kudu/tserver/scanners.h
index 1204860..5e425b2 100644
--- a/src/kudu/tserver/scanners.h
+++ b/src/kudu/tserver/scanners.h
@@ -28,7 +28,7 @@
#include "kudu/gutil/gscoped_ptr.h"
#include "kudu/gutil/macros.h"
#include "kudu/gutil/ref_counted.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/util/auto_release_pool.h"
#include "kudu/util/memory/arena.h"
#include "kudu/util/metrics.h"
@@ -71,7 +71,7 @@ class ScannerManager {
Status StartRemovalThread();
// Create a new scanner with a unique ID, inserting it into the map.
- void NewScanner(const scoped_refptr<tablet::TabletPeer>& tablet_peer,
+ void NewScanner(const scoped_refptr<tablet::TabletReplica>& tablet_replica,
const std::string& requestor_string,
uint64_t row_format_flags,
SharedScanner* scanner);
@@ -169,7 +169,7 @@ class ScopedUnregisterScanner {
class Scanner {
public:
Scanner(std::string id,
- const scoped_refptr<tablet::TabletPeer>& tablet_peer,
+ const scoped_refptr<tablet::TabletReplica>& tablet_replica,
std::string requestor_string, ScannerMetrics* metrics,
uint64_t row_format_flags);
~Scanner();
@@ -217,11 +217,11 @@ class Scanner {
const ScanSpec& spec() const;
const std::string& tablet_id() const {
- // scanners-test passes a null tablet_peer.
- return tablet_peer_ ? tablet_peer_->tablet_id() : kNullTabletId;
+ // scanners-test passes a null tablet_replica.
+ return tablet_replica_ ? tablet_replica_->tablet_id() : kNullTabletId;
}
- const scoped_refptr<tablet::TabletPeer>& tablet_peer() const { return tablet_peer_; }
+ const scoped_refptr<tablet::TabletReplica>& tablet_replica() const { return tablet_replica_; }
const std::string& requestor_string() const { return requestor_string_; }
@@ -287,7 +287,7 @@ class Scanner {
const std::string id_;
// Tablet associated with the scanner.
- const scoped_refptr<tablet::TabletPeer> tablet_peer_;
+ const scoped_refptr<tablet::TabletReplica> tablet_replica_;
// Information about the requestor. Populated from
// RpcContext::requestor_string().
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/tablet_copy-test-base.h
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_copy-test-base.h b/src/kudu/tserver/tablet_copy-test-base.h
index bb9bc45..6e14d30 100644
--- a/src/kudu/tserver/tablet_copy-test-base.h
+++ b/src/kudu/tserver/tablet_copy-test-base.h
@@ -47,13 +47,13 @@ class TabletCopyTest : public TabletServerTestBase {
// to test that we are anchoring correctly. Since GenerateTestData() does a
// Flush(), Log GC is allowed to eat the logs before we get around to
// starting a tablet copy session.
- tablet_peer_->log_anchor_registry()->Register(
+ tablet_replica_->log_anchor_registry()->Register(
consensus::MinimumOpId().index(), CURRENT_TEST_NAME(), &anchor_);
NO_FATALS(GenerateTestData());
}
virtual void TearDown() OVERRIDE {
- ASSERT_OK(tablet_peer_->log_anchor_registry()->Unregister(&anchor_));
+ ASSERT_OK(tablet_replica_->log_anchor_registry()->Unregister(&anchor_));
NO_FATALS(TabletServerTestBase::TearDown());
}
@@ -106,19 +106,19 @@ class TabletCopyTest : public TabletServerTestBase {
LOG_TIMING(INFO, "Loading test data") {
for (int row_id = 0; row_id < kNumLogRolls * kIncr; row_id += kIncr) {
InsertTestRowsRemote(0, row_id, kIncr);
- ASSERT_OK(tablet_peer_->tablet()->Flush());
- ASSERT_OK(tablet_peer_->log()->AllocateSegmentAndRollOver());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->log()->AllocateSegmentAndRollOver());
}
}
}
// Return the permananent_uuid of the local service.
const std::string GetLocalUUID() const {
- return tablet_peer_->permanent_uuid();
+ return tablet_replica_->permanent_uuid();
}
const std::string& GetTabletId() const {
- return tablet_peer_->tablet()->tablet_id();
+ return tablet_replica_->tablet()->tablet_id();
}
// Read a block file from the file system fully into memory and return a
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/tablet_copy_client-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_copy_client-test.cc b/src/kudu/tserver/tablet_copy_client-test.cc
index cf6cdd5..7c70688 100644
--- a/src/kudu/tserver/tablet_copy_client-test.cc
+++ b/src/kudu/tserver/tablet_copy_client-test.cc
@@ -46,12 +46,12 @@ class TabletCopyClientTest : public TabletCopyTest {
ASSERT_OK(fs_manager_->CreateInitialFileSystemLayout());
ASSERT_OK(fs_manager_->Open());
- tablet_peer_->WaitUntilConsensusRunning(MonoDelta::FromSeconds(10.0));
+ tablet_replica_->WaitUntilConsensusRunning(MonoDelta::FromSeconds(10.0));
rpc::MessengerBuilder(CURRENT_TEST_NAME()).Build(&messenger_);
client_.reset(new TabletCopyClient(GetTabletId(),
fs_manager_.get(),
messenger_));
- ASSERT_OK(GetRaftConfigLeader(tablet_peer_->consensus()
+ ASSERT_OK(GetRaftConfigLeader(tablet_replica_->consensus()
->ConsensusState(consensus::CONSENSUS_CONFIG_COMMITTED), &leader_));
HostPort host_port;
@@ -139,7 +139,7 @@ TEST_F(TabletCopyClientTest, TestDownloadWalSegment) {
ASSERT_TRUE(fs_manager_->Exists(path));
log::SegmentSequence local_segments;
- ASSERT_OK(tablet_peer_->log()->reader()->GetSegmentsSnapshot(&local_segments));
+ ASSERT_OK(tablet_replica_->log()->reader()->GetSegmentsSnapshot(&local_segments));
const scoped_refptr<log::ReadableLogSegment>& segment = local_segments[0];
string server_path = segment->path();
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/tablet_copy_client.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_copy_client.cc b/src/kudu/tserver/tablet_copy_client.cc
index 495074f..21c5630 100644
--- a/src/kudu/tserver/tablet_copy_client.cc
+++ b/src/kudu/tserver/tablet_copy_client.cc
@@ -34,7 +34,7 @@
#include "kudu/rpc/transfer.h"
#include "kudu/tablet/tablet.pb.h"
#include "kudu/tablet/tablet_bootstrap.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tserver/tablet_copy.pb.h"
#include "kudu/tserver/tablet_copy.proxy.h"
#include "kudu/tserver/tablet_server.h"
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/tablet_copy_client.h
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_copy_client.h b/src/kudu/tserver/tablet_copy_client.h
index 3545915..259196f 100644
--- a/src/kudu/tserver/tablet_copy_client.h
+++ b/src/kudu/tserver/tablet_copy_client.h
@@ -49,7 +49,7 @@ class RpcController;
namespace tablet {
class TabletMetadata;
-class TabletPeer;
+class TabletReplica;
class TabletStatusListener;
class TabletSuperBlockPB;
} // namespace tablet
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/tablet_copy_service-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_copy_service-test.cc b/src/kudu/tserver/tablet_copy_service-test.cc
index 72346f9..420bd28 100644
--- a/src/kudu/tserver/tablet_copy_service-test.cc
+++ b/src/kudu/tserver/tablet_copy_service-test.cc
@@ -443,7 +443,7 @@ TEST_F(TabletCopyServiceTest, TestFetchLog) {
// Fetch the local data.
log::SegmentSequence local_segments;
- ASSERT_OK(tablet_peer_->log()->reader()->GetSegmentsSnapshot(&local_segments));
+ ASSERT_OK(tablet_replica_->log()->reader()->GetSegmentsSnapshot(&local_segments));
uint64_t first_seg_seqno = (*local_segments.begin())->header().sequence_number();
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/tablet_copy_service.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_copy_service.cc b/src/kudu/tserver/tablet_copy_service.cc
index 74a34c5..cc5016b 100644
--- a/src/kudu/tserver/tablet_copy_service.cc
+++ b/src/kudu/tserver/tablet_copy_service.cc
@@ -30,8 +30,8 @@
#include "kudu/rpc/rpc_context.h"
#include "kudu/server/server_base.h"
#include "kudu/tserver/tablet_copy_source_session.h"
-#include "kudu/tserver/tablet_peer_lookup.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tserver/tablet_replica_lookup.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/util/crc.h"
#include "kudu/util/fault_injection.h"
#include "kudu/util/flag_tags.h"
@@ -74,7 +74,7 @@ namespace kudu {
using crc::Crc32c;
using server::ServerBase;
-using tablet::TabletPeer;
+using tablet::TabletReplica;
namespace tserver {
@@ -84,11 +84,11 @@ static MonoTime GetNewExpireTime() {
TabletCopyServiceImpl::TabletCopyServiceImpl(
ServerBase* server,
- TabletPeerLookupIf* tablet_peer_lookup)
+ TabletReplicaLookupIf* tablet_replica_lookup)
: TabletCopyServiceIf(server->metric_entity(), server->result_tracker()),
server_(server),
fs_manager_(CHECK_NOTNULL(server->fs_manager())),
- tablet_peer_lookup_(CHECK_NOTNULL(tablet_peer_lookup)),
+ tablet_replica_lookup_(CHECK_NOTNULL(tablet_replica_lookup)),
rand_(GetRandomSeed32()),
shutdown_latch_(1) {
CHECK_OK(Thread::Create("tablet-copy", "tc-session-exp",
@@ -117,8 +117,8 @@ void TabletCopyServiceImpl::BeginTabletCopySession(
// but there is no guarantee this will not change in the future.
const string session_id = Substitute("$0-$1", requestor_uuid, tablet_id);
- scoped_refptr<TabletPeer> tablet_peer;
- RPC_RETURN_NOT_OK(tablet_peer_lookup_->GetTabletPeer(tablet_id, &tablet_peer),
+ scoped_refptr<TabletReplica> tablet_replica;
+ RPC_RETURN_NOT_OK(tablet_replica_lookup_->GetTabletReplica(tablet_id, &tablet_replica),
TabletCopyErrorPB::TABLET_NOT_FOUND,
Substitute("Unable to find specified tablet: $0", tablet_id),
context);
@@ -132,7 +132,7 @@ void TabletCopyServiceImpl::BeginTabletCopySession(
"Beginning new tablet copy session on tablet $0 from peer $1"
" at $2: session id = $3",
tablet_id, requestor_uuid, context->requestor_string(), session_id);
- session.reset(new TabletCopySourceSession(tablet_peer, session_id,
+ session.reset(new TabletCopySourceSession(tablet_replica, session_id,
requestor_uuid, fs_manager_));
RPC_RETURN_NOT_OK(session->Init(),
TabletCopyErrorPB::UNKNOWN_ERROR,
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/tablet_copy_service.h
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_copy_service.h b/src/kudu/tserver/tablet_copy_service.h
index 81b1be2..c4f701e 100644
--- a/src/kudu/tserver/tablet_copy_service.h
+++ b/src/kudu/tserver/tablet_copy_service.h
@@ -45,12 +45,12 @@ class ReadableLogSegment;
namespace tserver {
class TabletCopySourceSession;
-class TabletPeerLookupIf;
+class TabletReplicaLookupIf;
class TabletCopyServiceImpl : public TabletCopyServiceIf {
public:
TabletCopyServiceImpl(server::ServerBase* server,
- TabletPeerLookupIf* tablet_peer_lookup);
+ TabletReplicaLookupIf* tablet_replica_lookup);
bool AuthorizeServiceUser(const google::protobuf::Message* req,
google::protobuf::Message* resp,
@@ -112,7 +112,7 @@ class TabletCopyServiceImpl : public TabletCopyServiceIf {
server::ServerBase* server_;
FsManager* fs_manager_;
- TabletPeerLookupIf* tablet_peer_lookup_;
+ TabletReplicaLookupIf* tablet_replica_lookup_;
// Protects sessions_ map.
mutable Mutex sessions_lock_;
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/tablet_copy_source_session-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_copy_source_session-test.cc b/src/kudu/tserver/tablet_copy_source_session-test.cc
index 80d270a..5c34774 100644
--- a/src/kudu/tserver/tablet_copy_source_session-test.cc
+++ b/src/kudu/tserver/tablet_copy_source_session-test.cc
@@ -34,7 +34,7 @@
#include "kudu/gutil/strings/substitute.h"
#include "kudu/rpc/messenger.h"
#include "kudu/tserver/tablet_copy_source_session.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/util/crc.h"
#include "kudu/util/metrics.h"
#include "kudu/util/pb_util.h"
@@ -64,7 +64,7 @@ using tablet::ColumnDataPB;
using tablet::DeltaDataPB;
using tablet::KuduTabletTest;
using tablet::RowSetDataPB;
-using tablet::TabletPeer;
+using tablet::TabletReplica;
using tablet::TabletSuperBlockPB;
using tablet::WriteTransactionState;
@@ -78,19 +78,19 @@ class TabletCopyTest : public KuduTabletTest {
virtual void SetUp() OVERRIDE {
NO_FATALS(KuduTabletTest::SetUp());
- NO_FATALS(SetUpTabletPeer());
+ NO_FATALS(SetUpTabletReplica());
NO_FATALS(PopulateTablet());
NO_FATALS(InitSession());
}
virtual void TearDown() OVERRIDE {
session_.reset();
- tablet_peer_->Shutdown();
+ tablet_replica_->Shutdown();
KuduTabletTest::TearDown();
}
protected:
- void SetUpTabletPeer() {
+ void SetUpTabletReplica() {
scoped_refptr<Log> log;
ASSERT_OK(Log::Open(LogOptions(), fs_manager(), tablet()->tablet_id(),
*tablet()->schema(),
@@ -106,15 +106,15 @@ class TabletCopyTest : public KuduTabletTest {
config_peer.mutable_last_known_addr()->set_port(0);
config_peer.set_member_type(RaftPeerPB::VOTER);
- tablet_peer_.reset(
- new TabletPeer(tablet()->metadata(),
- config_peer,
- apply_pool_.get(),
- Bind(&TabletCopyTest::TabletPeerStateChangedCallback,
- Unretained(this),
- tablet()->tablet_id())));
+ tablet_replica_.reset(
+ new TabletReplica(tablet()->metadata(),
+ config_peer,
+ apply_pool_.get(),
+ Bind(&TabletCopyTest::TabletReplicaStateChangedCallback,
+ Unretained(this),
+ tablet()->tablet_id())));
- // TODO(dralves) similar to code in tablet_peer-test, consider refactor.
+ // TODO(dralves) similar to code in tablet_replica-test, consider refactor.
RaftConfigPB config;
config.add_peers()->CopyFrom(config_peer);
config.set_opid_index(consensus::kInvalidOpIdIndex);
@@ -129,27 +129,27 @@ class TabletCopyTest : public KuduTabletTest {
mbuilder.Build(&messenger);
log_anchor_registry_.reset(new LogAnchorRegistry());
- tablet_peer_->SetBootstrapping();
- ASSERT_OK(tablet_peer_->Init(tablet(),
+ tablet_replica_->SetBootstrapping();
+ ASSERT_OK(tablet_replica_->Init(tablet(),
clock(),
messenger,
scoped_refptr<rpc::ResultTracker>(),
log,
metric_entity));
consensus::ConsensusBootstrapInfo boot_info;
- ASSERT_OK(tablet_peer_->Start(boot_info));
- ASSERT_OK(tablet_peer_->WaitUntilConsensusRunning(MonoDelta::FromSeconds(10)));
- ASSERT_OK(tablet_peer_->consensus()->WaitUntilLeaderForTests(MonoDelta::FromSeconds(10)));
+ ASSERT_OK(tablet_replica_->Start(boot_info));
+ ASSERT_OK(tablet_replica_->WaitUntilConsensusRunning(MonoDelta::FromSeconds(10)));
+ ASSERT_OK(tablet_replica_->consensus()->WaitUntilLeaderForTests(MonoDelta::FromSeconds(10)));
}
- void TabletPeerStateChangedCallback(const string& tablet_id, const string& reason) {
- LOG(INFO) << "Tablet peer state changed for tablet " << tablet_id << ". Reason: " << reason;
+ void TabletReplicaStateChangedCallback(const string& tablet_id, const string& reason) {
+ LOG(INFO) << "Tablet replica state changed for tablet " << tablet_id << ". Reason: " << reason;
}
void PopulateTablet() {
for (int32_t i = 0; i < 1000; i++) {
WriteRequestPB req;
- req.set_tablet_id(tablet_peer_->tablet_id());
+ req.set_tablet_id(tablet_replica_->tablet_id());
ASSERT_OK(SchemaToPB(client_schema_, req.mutable_schema()));
RowOperationsPB* data = req.mutable_row_operations();
RowOperationsPBEncoder enc(data);
@@ -164,13 +164,13 @@ class TabletCopyTest : public KuduTabletTest {
CountDownLatch latch(1);
unique_ptr<tablet::WriteTransactionState> state(
- new tablet::WriteTransactionState(tablet_peer_.get(),
+ new tablet::WriteTransactionState(tablet_replica_.get(),
&req,
nullptr, // No RequestIdPB
&resp));
state->set_completion_callback(gscoped_ptr<tablet::TransactionCompletionCallback>(
new tablet::LatchTransactionCompletionCallback<WriteResponsePB>(&latch, &resp)));
- ASSERT_OK(tablet_peer_->SubmitWrite(std::move(state)));
+ ASSERT_OK(tablet_replica_->SubmitWrite(std::move(state)));
latch.Wait();
ASSERT_FALSE(resp.has_error()) << "Request failed: " << SecureShortDebugString(resp.error());
ASSERT_EQ(0, resp.per_row_errors_size()) << "Insert error: " << SecureShortDebugString(resp);
@@ -179,7 +179,7 @@ class TabletCopyTest : public KuduTabletTest {
}
void InitSession() {
- session_.reset(new TabletCopySourceSession(tablet_peer_.get(), "TestSession", "FakeUUID",
+ session_.reset(new TabletCopySourceSession(tablet_replica_.get(), "TestSession", "FakeUUID",
fs_manager()));
ASSERT_OK(session_->Init());
}
@@ -214,7 +214,7 @@ class TabletCopyTest : public KuduTabletTest {
MetricRegistry metric_registry_;
scoped_refptr<LogAnchorRegistry> log_anchor_registry_;
gscoped_ptr<ThreadPool> apply_pool_;
- scoped_refptr<TabletPeer> tablet_peer_;
+ scoped_refptr<TabletReplica> tablet_replica_;
scoped_refptr<TabletCopySourceSession> session_;
};
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/tablet_copy_source_session.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_copy_source_session.cc b/src/kudu/tserver/tablet_copy_source_session.cc
index 17b73f7..6021e85 100644
--- a/src/kudu/tserver/tablet_copy_source_session.cc
+++ b/src/kudu/tserver/tablet_copy_source_session.cc
@@ -27,7 +27,7 @@
#include "kudu/gutil/strings/substitute.h"
#include "kudu/gutil/type_traits.h"
#include "kudu/rpc/transfer.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/util/flag_tags.h"
#include "kudu/util/mutex.h"
#include "kudu/util/pb_util.h"
@@ -50,12 +50,12 @@ using std::shared_ptr;
using std::unique_ptr;
using strings::Substitute;
using tablet::TabletMetadata;
-using tablet::TabletPeer;
+using tablet::TabletReplica;
TabletCopySourceSession::TabletCopySourceSession(
- const scoped_refptr<TabletPeer>& tablet_peer, std::string session_id,
+ const scoped_refptr<TabletReplica>& tablet_replica, std::string session_id,
std::string requestor_uuid, FsManager* fs_manager)
- : tablet_peer_(tablet_peer),
+ : tablet_replica_(tablet_replica),
session_id_(std::move(session_id)),
requestor_uuid_(std::move(requestor_uuid)),
fs_manager_(fs_manager),
@@ -71,17 +71,17 @@ Status TabletCopySourceSession::Init() {
MutexLock l(session_lock_);
CHECK(!initted_);
- RETURN_NOT_OK(tablet_peer_->CheckRunning());
+ RETURN_NOT_OK(tablet_replica_->CheckRunning());
- const string& tablet_id = tablet_peer_->tablet_id();
+ const string& tablet_id = tablet_replica_->tablet_id();
// Prevent log GC while we grab log segments and Tablet metadata.
string anchor_owner_token = Substitute("TabletCopy-$0", session_id_);
- tablet_peer_->log_anchor_registry()->Register(
+ tablet_replica_->log_anchor_registry()->Register(
MinimumOpId().index(), anchor_owner_token, &log_anchor_);
// Read the SuperBlock from disk.
- const scoped_refptr<TabletMetadata>& metadata = tablet_peer_->tablet_metadata();
+ const scoped_refptr<TabletMetadata>& metadata = tablet_replica_->tablet_metadata();
RETURN_NOT_OK_PREPEND(metadata->ReadSuperBlockFromDisk(&tablet_superblock_),
Substitute("Unable to access superblock for tablet $0",
tablet_id));
@@ -98,14 +98,14 @@ Status TabletCopySourceSession::Init() {
// Get the latest opid in the log at this point in time so we can re-anchor.
OpId last_logged_opid;
- CHECK_NOTNULL(tablet_peer_->log())->GetLatestEntryOpId(&last_logged_opid);
+ CHECK_NOTNULL(tablet_replica_->log())->GetLatestEntryOpId(&last_logged_opid);
// Get the current segments from the log, including the active segment.
// The Log doesn't add the active segment to the log reader's list until
// a header has been written to it (but it will not have a footer).
- shared_ptr<log::LogReader> reader = tablet_peer_->log()->reader();
+ shared_ptr<log::LogReader> reader = tablet_replica_->log()->reader();
if (!reader) {
- tablet::TabletStatePB tablet_state = tablet_peer_->state();
+ tablet::TabletStatePB tablet_state = tablet_replica_->state();
return Status::IllegalState(Substitute(
"Unable to initialize tablet copy session for tablet $0. "
"Log reader is not available. Tablet state: $1 ($2)",
@@ -120,9 +120,9 @@ Status TabletCopySourceSession::Init() {
// We do this after snapshotting the log to avoid a scenario where the latest
// entry in the log has a term higher than the term stored in the consensus
// metadata, which will results in a CHECK failure on RaftConsensus init.
- scoped_refptr<consensus::Consensus> consensus = tablet_peer_->shared_consensus();
+ scoped_refptr<consensus::Consensus> consensus = tablet_replica_->shared_consensus();
if (!consensus) {
- tablet::TabletStatePB tablet_state = tablet_peer_->state();
+ tablet::TabletStatePB tablet_state = tablet_replica_->state();
return Status::IllegalState(Substitute(
"Unable to initialize tablet copy session for tablet $0. "
"Consensus is not available. Tablet state: $1 ($2)",
@@ -135,7 +135,7 @@ Status TabletCopySourceSession::Init() {
// tablet copy loop due to a follower falling too far behind the
// leader's log when tablet copy is slow. The remote controls when
// this anchor is released by ending the tablet copy session.
- RETURN_NOT_OK(tablet_peer_->log_anchor_registry()->UpdateRegistration(
+ RETURN_NOT_OK(tablet_replica_->log_anchor_registry()->UpdateRegistration(
last_logged_opid.index(), anchor_owner_token, &log_anchor_));
LOG(INFO) << Substitute(
@@ -147,7 +147,7 @@ Status TabletCopySourceSession::Init() {
const std::string& TabletCopySourceSession::tablet_id() const {
DCHECK(initted_);
- return tablet_peer_->tablet_id();
+ return tablet_replica_->tablet_id();
}
const std::string& TabletCopySourceSession::requestor_uuid() const {
@@ -377,7 +377,7 @@ Status TabletCopySourceSession::FindLogSegment(uint64_t segment_seqno,
}
Status TabletCopySourceSession::UnregisterAnchorIfNeededUnlocked() {
- return tablet_peer_->log_anchor_registry()->UnregisterIfAnchored(&log_anchor_);
+ return tablet_replica_->log_anchor_registry()->UnregisterIfAnchored(&log_anchor_);
}
} // namespace tserver
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/tablet_copy_source_session.h
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_copy_source_session.h b/src/kudu/tserver/tablet_copy_source_session.h
index 0d8aad1..2615869 100644
--- a/src/kudu/tserver/tablet_copy_source_session.h
+++ b/src/kudu/tserver/tablet_copy_source_session.h
@@ -41,12 +41,12 @@ namespace kudu {
class FsManager;
namespace tablet {
-class TabletPeer;
+class TabletReplica;
} // namespace tablet
namespace tserver {
-class TabletPeerLookupIf;
+class TabletReplicaLookupIf;
// Caches file size and holds a shared_ptr reference to a RandomAccessFile.
// Assumes that the file underlying the RandomAccessFile is immutable.
@@ -86,9 +86,9 @@ struct ImmutableReadableBlockInfo {
// on expiration while it is in use by another thread.
class TabletCopySourceSession : public RefCountedThreadSafe<TabletCopySourceSession> {
public:
- TabletCopySourceSession(const scoped_refptr<tablet::TabletPeer>& tablet_peer,
- std::string session_id, std::string requestor_uuid,
- FsManager* fs_manager);
+ TabletCopySourceSession(const scoped_refptr<tablet::TabletReplica>& tablet_replica,
+ std::string session_id, std::string requestor_uuid,
+ FsManager* fs_manager);
// Initialize the session, including anchoring files (TODO) and fetching the
// tablet superblock and list of WAL segments.
@@ -172,7 +172,7 @@ class TabletCopySourceSession : public RefCountedThreadSafe<TabletCopySourceSess
// Unregister log anchor, if it's registered.
Status UnregisterAnchorIfNeededUnlocked();
- scoped_refptr<tablet::TabletPeer> tablet_peer_;
+ scoped_refptr<tablet::TabletReplica> tablet_replica_;
const std::string session_id_;
const std::string requestor_uuid_;
FsManager* const fs_manager_;
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/tablet_peer_lookup.h
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_peer_lookup.h b/src/kudu/tserver/tablet_peer_lookup.h
deleted file mode 100644
index 70901fd..0000000
--- a/src/kudu/tserver/tablet_peer_lookup.h
+++ /dev/null
@@ -1,63 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-#ifndef KUDU_TSERVER_TABLET_PEER_LOOKUP_H_
-#define KUDU_TSERVER_TABLET_PEER_LOOKUP_H_
-
-#include <boost/optional/optional_fwd.hpp>
-#include <functional>
-#include <memory>
-#include <string>
-
-#include "kudu/gutil/ref_counted.h"
-#include "kudu/tserver/tserver.pb.h"
-#include "kudu/util/status.h"
-
-namespace kudu {
-
-class HostPort;
-class NodeInstancePB;
-
-namespace consensus {
-class StartTabletCopyRequestPB;
-} // namespace consensus
-
-namespace tablet {
-class TabletPeer;
-} // namespace tablet
-
-namespace tserver {
-
-// Pure virtual interface that provides an abstraction for something that
-// contains and manages TabletPeers. This interface is implemented on both
-// tablet servers and master servers.
-// TODO: Rename this interface.
-class TabletPeerLookupIf {
- public:
- virtual Status GetTabletPeer(const std::string& tablet_id,
- scoped_refptr<tablet::TabletPeer>* tablet_peer) const = 0;
-
- virtual const NodeInstancePB& NodeInstance() const = 0;
-
- virtual void StartTabletCopy(
- const consensus::StartTabletCopyRequestPB* req,
- std::function<void(const Status&, TabletServerErrorPB::Code)> cb) = 0;
-};
-
-} // namespace tserver
-} // namespace kudu
-
-#endif // KUDU_TSERVER_TABLET_PEER_LOOKUP_H_
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/tablet_replica_lookup.h
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_replica_lookup.h b/src/kudu/tserver/tablet_replica_lookup.h
new file mode 100644
index 0000000..6e91af2
--- /dev/null
+++ b/src/kudu/tserver/tablet_replica_lookup.h
@@ -0,0 +1,63 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+#ifndef KUDU_TSERVER_TABLET_REPLICA_LOOKUP_H_
+#define KUDU_TSERVER_TABLET_REPLICA_LOOKUP_H_
+
+#include <boost/optional/optional_fwd.hpp>
+#include <functional>
+#include <memory>
+#include <string>
+
+#include "kudu/gutil/ref_counted.h"
+#include "kudu/tserver/tserver.pb.h"
+#include "kudu/util/status.h"
+
+namespace kudu {
+
+class HostPort;
+class NodeInstancePB;
+
+namespace consensus {
+class StartTabletCopyRequestPB;
+} // namespace consensus
+
+namespace tablet {
+class TabletReplica;
+} // namespace tablet
+
+namespace tserver {
+
+// Pure virtual interface that provides an abstraction for something that
+// contains and manages TabletReplicas. This interface is implemented on both
+// tablet servers and master servers.
+// TODO: Rename this interface.
+class TabletReplicaLookupIf {
+ public:
+ virtual Status GetTabletReplica(const std::string& tablet_id,
+ scoped_refptr<tablet::TabletReplica>* tablet_replica) const = 0;
+
+ virtual const NodeInstancePB& NodeInstance() const = 0;
+
+ virtual void StartTabletCopy(
+ const consensus::StartTabletCopyRequestPB* req,
+ std::function<void(const Status&, TabletServerErrorPB::Code)> cb) = 0;
+};
+
+} // namespace tserver
+} // namespace kudu
+
+#endif // KUDU_TSERVER_TABLET_REPLICA_LOOKUP_H_
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/tablet_server-test-base.h
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_server-test-base.h b/src/kudu/tserver/tablet_server-test-base.h
index 29495dc..178bb11 100644
--- a/src/kudu/tserver/tablet_server-test-base.h
+++ b/src/kudu/tserver/tablet_server-test-base.h
@@ -41,7 +41,7 @@
#include "kudu/server/server_base.proxy.h"
#include "kudu/tablet/local_tablet_writer.h"
#include "kudu/tablet/tablet.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tserver/mini_tablet_server.h"
#include "kudu/tserver/tablet_copy.proxy.h"
#include "kudu/tserver/scanners.h"
@@ -107,7 +107,8 @@ class TabletServerTestBase : public KuduTest {
// Set up a tablet inside the server.
ASSERT_OK(mini_server_->AddTestTablet(kTableId, kTabletId, schema_));
- ASSERT_TRUE(mini_server_->server()->tablet_manager()->LookupTablet(kTabletId, &tablet_peer_));
+ ASSERT_TRUE(mini_server_->server()->tablet_manager()->LookupTablet(kTabletId,
+ &tablet_replica_));
// Creating a tablet is async, we wait here instead of having to handle errors later.
ASSERT_OK(WaitForTabletRunning(kTabletId));
@@ -117,10 +118,11 @@ class TabletServerTestBase : public KuduTest {
}
Status WaitForTabletRunning(const char *tablet_id) {
- scoped_refptr<tablet::TabletPeer> tablet_peer;
- RETURN_NOT_OK(mini_server_->server()->tablet_manager()->GetTabletPeer(tablet_id, &tablet_peer));
- RETURN_NOT_OK(tablet_peer->WaitUntilConsensusRunning(MonoDelta::FromSeconds(10)));
- RETURN_NOT_OK(tablet_peer->consensus()->WaitUntilLeaderForTests(MonoDelta::FromSeconds(10)));
+ scoped_refptr<tablet::TabletReplica> tablet_replica;
+ RETURN_NOT_OK(mini_server_->server()->tablet_manager()->GetTabletReplica(tablet_id,
+ &tablet_replica));
+ RETURN_NOT_OK(tablet_replica->WaitUntilConsensusRunning(MonoDelta::FromSeconds(10)));
+ RETURN_NOT_OK(tablet_replica->consensus()->WaitUntilLeaderForTests(MonoDelta::FromSeconds(10)));
return Status::OK();
}
@@ -158,7 +160,7 @@ class TabletServerTestBase : public KuduTest {
// Inserts 'num_rows' test rows directly into the tablet (i.e not via RPC)
void InsertTestRowsDirect(int64_t start_row, uint64_t num_rows) {
- tablet::LocalTabletWriter writer(tablet_peer_->tablet(), &schema_);
+ tablet::LocalTabletWriter writer(tablet_replica_->tablet(), &schema_);
KuduPartialRow row(&schema_);
for (int64_t i = 0; i < num_rows; i++) {
BuildTestRow(start_row + i, &row);
@@ -329,9 +331,9 @@ class TabletServerTestBase : public KuduTest {
void ShutdownTablet() {
if (mini_server_.get()) {
- // The tablet peer must be destroyed before the TS, otherwise data
+ // The TabletReplica must be destroyed before the TS, otherwise data
// blocks may be destroyed after their owning block manager.
- tablet_peer_.reset();
+ tablet_replica_.reset();
mini_server_->Shutdown();
mini_server_.reset();
}
@@ -347,11 +349,11 @@ class TabletServerTestBase : public KuduTest {
// this should open the tablet created on StartTabletServer()
RETURN_NOT_OK(mini_server_->Start());
- // Don't RETURN_NOT_OK immediately -- even if we fail, we may still get a TabletPeer object
+ // Don't RETURN_NOT_OK immediately -- even if we fail, we may still get a TabletReplica object
// which has information about the failure.
Status wait_status = mini_server_->WaitStarted();
bool found_peer = mini_server_->server()->tablet_manager()->LookupTablet(
- kTabletId, &tablet_peer_);
+ kTabletId, &tablet_replica_);
RETURN_NOT_OK(wait_status);
if (!found_peer) {
return Status::NotFound("Tablet was not found");
@@ -368,7 +370,7 @@ class TabletServerTestBase : public KuduTest {
// Verifies that a set of expected rows (key, value) is present in the tablet.
void VerifyRows(const Schema& schema, const vector<KeyValue>& expected) {
gscoped_ptr<RowwiseIterator> iter;
- ASSERT_OK(tablet_peer_->tablet()->NewRowIterator(schema, &iter));
+ ASSERT_OK(tablet_replica_->tablet()->NewRowIterator(schema, &iter));
ASSERT_OK(iter->Init(NULL));
int batch_size = std::max(
@@ -456,7 +458,7 @@ class TabletServerTestBase : public KuduTest {
std::shared_ptr<rpc::Messenger> client_messenger_;
gscoped_ptr<MiniTabletServer> mini_server_;
- scoped_refptr<tablet::TabletPeer> tablet_peer_;
+ scoped_refptr<tablet::TabletReplica> tablet_replica_;
gscoped_ptr<TabletServerServiceProxy> proxy_;
gscoped_ptr<TabletServerAdminServiceProxy> admin_proxy_;
gscoped_ptr<consensus::ConsensusServiceProxy> consensus_proxy_;
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/tablet_server-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_server-test.cc b/src/kudu/tserver/tablet_server-test.cc
index f4ba760..43f01a6 100644
--- a/src/kudu/tserver/tablet_server-test.cc
+++ b/src/kudu/tserver/tablet_server-test.cc
@@ -44,7 +44,7 @@ using kudu::rpc::RpcController;
using kudu::server::Clock;
using kudu::server::HybridClock;
using kudu::tablet::Tablet;
-using kudu::tablet::TabletPeer;
+using kudu::tablet::TabletReplica;
using std::shared_ptr;
using std::string;
using std::unique_ptr;
@@ -271,7 +271,7 @@ TEST_F(TabletServerTest, TestInsert) {
WriteResponsePB resp;
RpcController controller;
- scoped_refptr<TabletPeer> tablet;
+ scoped_refptr<TabletReplica> tablet;
ASSERT_TRUE(mini_server_->server()->tablet_manager()->LookupTablet(kTabletId, &tablet));
scoped_refptr<Counter> rows_inserted =
METRIC_rows_inserted.Instantiate(tablet->tablet()->GetMetricEntity());
@@ -375,7 +375,7 @@ TEST_F(TabletServerTest, TestExternalConsistencyModes_ClientPropagated) {
WriteResponsePB resp;
RpcController controller;
- scoped_refptr<TabletPeer> tablet;
+ scoped_refptr<TabletReplica> tablet;
ASSERT_TRUE(
mini_server_->server()->tablet_manager()->LookupTablet(kTabletId,
&tablet));
@@ -426,7 +426,7 @@ TEST_F(TabletServerTest, TestExternalConsistencyModes_CommitWait) {
RpcController controller;
HybridClock* hclock = down_cast<HybridClock*, Clock>(mini_server_->server()->clock());
- scoped_refptr<TabletPeer> tablet;
+ scoped_refptr<TabletReplica> tablet;
ASSERT_TRUE(
mini_server_->server()->tablet_manager()->LookupTablet(kTabletId,
&tablet));
@@ -490,7 +490,7 @@ TEST_F(TabletServerTest, TestExternalConsistencyModes_CommitWait) {
TEST_F(TabletServerTest, TestInsertAndMutate) {
- scoped_refptr<TabletPeer> tablet;
+ scoped_refptr<TabletReplica> tablet;
ASSERT_TRUE(mini_server_->server()->tablet_manager()->LookupTablet(kTabletId, &tablet));
scoped_refptr<Counter> rows_inserted =
METRIC_rows_inserted.Instantiate(tablet->tablet()->GetMetricEntity());
@@ -779,11 +779,11 @@ TEST_F(TabletServerTest, TestRecoveryWithMutationsWhileFlushing) {
shared_ptr<MyCommonHooks> hooks(new MyCommonHooks(this));
- tablet_peer_->tablet()->SetFlushHooksForTests(hooks);
- tablet_peer_->tablet()->SetCompactionHooksForTests(hooks);
- tablet_peer_->tablet()->SetFlushCompactCommonHooksForTests(hooks);
+ tablet_replica_->tablet()->SetFlushHooksForTests(hooks);
+ tablet_replica_->tablet()->SetCompactionHooksForTests(hooks);
+ tablet_replica_->tablet()->SetFlushCompactCommonHooksForTests(hooks);
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
// Shutdown the tserver and try and rebuild the tablet from the log
// produced on recovery (recovery flushed no state, but produced a new
@@ -819,12 +819,12 @@ TEST_F(TabletServerTest, TestRecoveryWithMutationsWhileFlushingAndCompacting) {
shared_ptr<MyCommonHooks> hooks(new MyCommonHooks(this));
- tablet_peer_->tablet()->SetFlushHooksForTests(hooks);
- tablet_peer_->tablet()->SetCompactionHooksForTests(hooks);
- tablet_peer_->tablet()->SetFlushCompactCommonHooksForTests(hooks);
+ tablet_replica_->tablet()->SetFlushHooksForTests(hooks);
+ tablet_replica_->tablet()->SetCompactionHooksForTests(hooks);
+ tablet_replica_->tablet()->SetFlushCompactCommonHooksForTests(hooks);
// flush the first time
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
ASSERT_NO_FATAL_FAILURE(ShutdownAndRebuildTablet());
VerifyRows(schema_, { KeyValue(1, 10),
@@ -837,9 +837,9 @@ TEST_F(TabletServerTest, TestRecoveryWithMutationsWhileFlushingAndCompacting) {
hooks->increment_iteration();
// set the hooks on the new tablet
- tablet_peer_->tablet()->SetFlushHooksForTests(hooks);
- tablet_peer_->tablet()->SetCompactionHooksForTests(hooks);
- tablet_peer_->tablet()->SetFlushCompactCommonHooksForTests(hooks);
+ tablet_replica_->tablet()->SetFlushHooksForTests(hooks);
+ tablet_replica_->tablet()->SetCompactionHooksForTests(hooks);
+ tablet_replica_->tablet()->SetFlushCompactCommonHooksForTests(hooks);
// insert an additional row so that we can flush
InsertTestRowsRemote(0, 8, 1);
@@ -847,7 +847,7 @@ TEST_F(TabletServerTest, TestRecoveryWithMutationsWhileFlushingAndCompacting) {
// flush an additional MRS so that we have two DiskRowSets and then compact
// them making sure that mutations executed mid compaction are replayed as
// expected
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
VerifyRows(schema_, { KeyValue(1, 11),
KeyValue(2, 21),
KeyValue(3, 31),
@@ -858,7 +858,7 @@ TEST_F(TabletServerTest, TestRecoveryWithMutationsWhileFlushingAndCompacting) {
KeyValue(8, 8) });
hooks->increment_iteration();
- ASSERT_OK(tablet_peer_->tablet()->Compact(Tablet::FORCE_COMPACT_ALL));
+ ASSERT_OK(tablet_replica_->tablet()->Compact(Tablet::FORCE_COMPACT_ALL));
// get the clock's current timestamp
Timestamp now_before = mini_server_->server()->clock()->Now();
@@ -891,21 +891,21 @@ TEST_F(TabletServerTest, TestKUDU_176_RecoveryAfterMajorDeltaCompaction) {
// Flush a DRS with 1 rows.
ASSERT_NO_FATAL_FAILURE(InsertTestRowsRemote(0, 1, 1));
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
ANFF(VerifyRows(schema_, { KeyValue(1, 1) }));
// Update it, flush deltas.
ANFF(UpdateTestRowRemote(0, 1, 2));
- ASSERT_OK(tablet_peer_->tablet()->FlushBiggestDMS());
+ ASSERT_OK(tablet_replica_->tablet()->FlushBiggestDMS());
ANFF(VerifyRows(schema_, { KeyValue(1, 2) }));
// Major compact deltas.
{
vector<shared_ptr<tablet::RowSet> > rsets;
- tablet_peer_->tablet()->GetRowSetsForTests(&rsets);
- vector<ColumnId> col_ids = { tablet_peer_->tablet()->schema()->column_id(1),
- tablet_peer_->tablet()->schema()->column_id(2) };
- ASSERT_OK(tablet_peer_->tablet()->DoMajorDeltaCompaction(col_ids, rsets[0]))
+ tablet_replica_->tablet()->GetRowSetsForTests(&rsets);
+ vector<ColumnId> col_ids = { tablet_replica_->tablet()->schema()->column_id(1),
+ tablet_replica_->tablet()->schema()->column_id(2) };
+ ASSERT_OK(tablet_replica_->tablet()->DoMajorDeltaCompaction(col_ids, rsets[0]))
}
// Verify that data is still the same.
@@ -925,7 +925,7 @@ TEST_F(TabletServerTest, TestKUDU_1341) {
for (int i = 0; i < 3; i++) {
// Insert a row to DMS and flush it.
ANFF(InsertTestRowsRemote(kTid, 1, 1));
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
// Update and delete row (in DMS)
ANFF(UpdateTestRowRemote(kTid, 1, i));
@@ -936,18 +936,18 @@ TEST_F(TabletServerTest, TestKUDU_1341) {
// flush.
ANFF(InsertTestRowsRemote(kTid, 1, 1));
ANFF(UpdateTestRowRemote(kTid, 1, 12345));
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
ANFF(VerifyRows(schema_, { KeyValue(1, 12345) }));
// Test restart.
ASSERT_OK(ShutdownAndRebuildTablet());
ANFF(VerifyRows(schema_, { KeyValue(1, 12345) }));
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
ANFF(VerifyRows(schema_, { KeyValue(1, 12345) }));
// Test compaction after restart.
- ASSERT_OK(tablet_peer_->tablet()->Compact(Tablet::FORCE_COMPACT_ALL));
+ ASSERT_OK(tablet_replica_->tablet()->Compact(Tablet::FORCE_COMPACT_ALL));
ANFF(VerifyRows(schema_, { KeyValue(1, 12345) }));
}
@@ -1016,12 +1016,12 @@ TEST_F(TabletServerTest, DISABLED_TestExactlyOnceForErrorsAcrossRestart) {
TEST_F(TabletServerTest, TestKUDU_177_RecoveryOfDMSEditsAfterMajorDeltaCompaction) {
// Flush a DRS with 1 rows.
ANFF(InsertTestRowsRemote(0, 1, 1));
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
ANFF(VerifyRows(schema_, { KeyValue(1, 1) }));
// Update it, flush deltas.
ANFF(UpdateTestRowRemote(0, 1, 2));
- ASSERT_OK(tablet_peer_->tablet()->FlushBiggestDMS());
+ ASSERT_OK(tablet_replica_->tablet()->FlushBiggestDMS());
// Update it again, so this last update is in the DMS.
ANFF(UpdateTestRowRemote(0, 1, 3));
@@ -1031,10 +1031,10 @@ TEST_F(TabletServerTest, TestKUDU_177_RecoveryOfDMSEditsAfterMajorDeltaCompactio
// DMS should "move over" to the output of the delta compaction.
{
vector<shared_ptr<tablet::RowSet> > rsets;
- tablet_peer_->tablet()->GetRowSetsForTests(&rsets);
- vector<ColumnId> col_ids = { tablet_peer_->tablet()->schema()->column_id(1),
- tablet_peer_->tablet()->schema()->column_id(2) };
- ASSERT_OK(tablet_peer_->tablet()->DoMajorDeltaCompaction(col_ids, rsets[0]));
+ tablet_replica_->tablet()->GetRowSetsForTests(&rsets);
+ vector<ColumnId> col_ids = { tablet_replica_->tablet()->schema()->column_id(1),
+ tablet_replica_->tablet()->schema()->column_id(2) };
+ ASSERT_OK(tablet_replica_->tablet()->DoMajorDeltaCompaction(col_ids, rsets[0]));
}
// Verify that data is still the same.
ANFF(VerifyRows(schema_, { KeyValue(1, 3) }));
@@ -1047,11 +1047,11 @@ TEST_F(TabletServerTest, TestKUDU_177_RecoveryOfDMSEditsAfterMajorDeltaCompactio
TEST_F(TabletServerTest, TestClientGetsErrorBackWhenRecoveryFailed) {
ANFF(InsertTestRowsRemote(0, 1, 7));
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
// Save the log path before shutting down the tablet (and destroying
- // the tablet peer).
- string log_path = tablet_peer_->log()->ActiveSegmentPathForTests();
+ // the TabletReplica).
+ string log_path = tablet_replica_->log()->ActiveSegmentPathForTests();
ShutdownTablet();
ASSERT_OK(log::CorruptLogFile(env_, log_path, log::FLIP_BYTE, 300));
@@ -1074,8 +1074,8 @@ TEST_F(TabletServerTest, TestClientGetsErrorBackWhenRecoveryFailed) {
ASSERT_EQ(TabletServerErrorPB::TABLET_NOT_RUNNING, resp.error().code());
ASSERT_STR_CONTAINS(resp.error().status().message(), "Tablet not RUNNING: FAILED");
- // Check that the tablet peer's status message is updated with the failure.
- ASSERT_STR_CONTAINS(tablet_peer_->last_status(),
+ // Check that the TabletReplica's status message is updated with the failure.
+ ASSERT_STR_CONTAINS(tablet_replica_->last_status(),
"Log file corruption detected");
}
@@ -1286,7 +1286,7 @@ TEST_F(TabletServerTest, TestSnapshotScan_OpenScanner) {
vector<uint64_t> write_timestamps_collector;
// Write and flush and write, so we have some rows in MRS and DRS
InsertTestRowsRemote(0, 0, 100, 2, nullptr, kTabletId, &write_timestamps_collector);
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
InsertTestRowsRemote(0, 100, 100, 2, nullptr, kTabletId, &write_timestamps_collector);
ScanRequestPB req;
@@ -1326,7 +1326,7 @@ TEST_F(TabletServerTest, TestSnapshotScan_LastRow) {
// Generate some interleaved rows
for (int i = 0; i < batch_size; i++) {
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
for (int j = 0; j < num_rows; j++) {
if (j % batch_size == i) {
InsertTestRowsDirect(j, 1);
@@ -1717,7 +1717,7 @@ TEST_F(TabletServerTest, TestInvalidScanRequest_BadProjectionTypes) {
// Column IDs are assigned to the user request schema on the tablet server
// based on the latest schema.
TEST_F(TabletServerTest, TestInvalidScanRequest_WithIds) {
- const Schema* projection = tablet_peer_->tablet()->schema();
+ const Schema* projection = tablet_replica_->tablet()->schema();
ASSERT_TRUE(projection->has_column_ids());
VerifyScanRequestFailure(*projection,
TabletServerErrorPB::INVALID_SCHEMA,
@@ -1809,9 +1809,9 @@ TEST_F(TabletServerTest, TestScan_KeepAliveExpiredScanner) {
void TabletServerTest::DoOrderedScanTest(const Schema& projection,
const string& expected_rows_as_string) {
InsertTestRowsDirect(0, 10);
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
InsertTestRowsDirect(10, 10);
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
InsertTestRowsDirect(20, 10);
ScanResponsePB resp;
@@ -1911,7 +1911,7 @@ TEST_F(TabletServerTest, TestAlterSchema) {
{
InsertTestRowsRemote(0, 2, 2);
- scoped_refptr<TabletPeer> tablet;
+ scoped_refptr<TabletReplica> tablet;
ASSERT_TRUE(mini_server_->server()->tablet_manager()->LookupTablet(kTabletId, &tablet));
ASSERT_OK(tablet->tablet()->Flush());
}
@@ -2006,7 +2006,7 @@ TEST_F(TabletServerTest, TestCreateTablet_TabletExists) {
}
TEST_F(TabletServerTest, TestDeleteTablet) {
- scoped_refptr<TabletPeer> tablet;
+ scoped_refptr<TabletReplica> tablet;
// Verify that the tablet exists
ASSERT_TRUE(mini_server_->server()->tablet_manager()->LookupTablet(kTabletId, &tablet));
@@ -2024,7 +2024,7 @@ TEST_F(TabletServerTest, TestDeleteTablet) {
// Put some data in the tablet. We flush and insert more rows to ensure that
// there is data both in the MRS and on disk.
ASSERT_NO_FATAL_FAILURE(InsertTestRowsRemote(0, 1, 1));
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
ASSERT_NO_FATAL_FAILURE(InsertTestRowsRemote(0, 2, 1));
const int block_count_after_flush = ondisk->value();
@@ -2035,7 +2035,7 @@ TEST_F(TabletServerTest, TestDeleteTablet) {
// Drop any local references to the tablet from within this test,
// so that when we delete it on the server, it's not held alive
// by the test code.
- tablet_peer_.reset();
+ tablet_replica_.reset();
tablet.reset();
DeleteTabletRequestPB req;
@@ -2101,7 +2101,7 @@ TEST_F(TabletServerTest, TestDeleteTablet_TabletNotCreated) {
// the other fails, with no assertion failures. Regression test for KUDU-345.
TEST_F(TabletServerTest, TestConcurrentDeleteTablet) {
// Verify that the tablet exists
- scoped_refptr<TabletPeer> tablet;
+ scoped_refptr<TabletReplica> tablet;
ASSERT_TRUE(mini_server_->server()->tablet_manager()->LookupTablet(kTabletId, &tablet));
static const int kNumDeletes = 2;
@@ -2390,15 +2390,15 @@ TEST_F(TabletServerTest, TestKudu120PreRequisites) {
// Insert a few rows...
InsertTestRowsRemote(0, 0, 10);
// ... now flush ...
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
// ... insert a few rows...
InsertTestRowsRemote(0, 10, 10);
// ... and flush again so that we have two disk row sets.
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
// Add a hook so that we can make the log wait right after an append
// (before the callback is triggered).
- log::Log* log = tablet_peer_->log();
+ log::Log* log = tablet_replica_->log();
shared_ptr<DelayFsyncLogHook> log_hook(new DelayFsyncLogHook);
log->SetLogFaultHooksForTests(log_hook);
@@ -2418,7 +2418,7 @@ TEST_F(TabletServerTest, TestKudu120PreRequisites) {
CountDownLatch flush_done_latch(1);
CHECK_OK(kudu::Thread::Create("CompactThread", "CompactThread",
CompactAsync,
- tablet_peer_->tablet(),
+ tablet_replica_->tablet(),
&flush_done_latch,
&flush_thread));
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tserver/tablet_service.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_service.cc b/src/kudu/tserver/tablet_service.cc
index e5df72c..4f3eab8 100644
--- a/src/kudu/tserver/tablet_service.cc
+++ b/src/kudu/tserver/tablet_service.cc
@@ -41,7 +41,7 @@
#include "kudu/tablet/metadata.pb.h"
#include "kudu/tablet/tablet_bootstrap.h"
#include "kudu/tablet/tablet_metrics.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tablet/transactions/alter_schema_transaction.h"
#include "kudu/tablet/transactions/write_transaction.h"
#include "kudu/tserver/tablet_copy_service.h"
@@ -125,7 +125,7 @@ using kudu::rpc::RpcSidecar;
using kudu::server::ServerBase;
using kudu::tablet::AlterSchemaTransactionState;
using kudu::tablet::Tablet;
-using kudu::tablet::TabletPeer;
+using kudu::tablet::TabletReplica;
using kudu::tablet::TabletStatusPB;
using kudu::tablet::TransactionCompletionCallback;
using kudu::tablet::WriteTransactionState;
@@ -152,12 +152,12 @@ namespace {
//
// Returns true if successful.
template<class RespClass>
-bool LookupTabletPeerOrRespond(TabletPeerLookupIf* tablet_manager,
- const string& tablet_id,
- RespClass* resp,
- rpc::RpcContext* context,
- scoped_refptr<TabletPeer>* peer) {
- if (PREDICT_FALSE(!tablet_manager->GetTabletPeer(tablet_id, peer).ok())) {
+bool LookupTabletReplicaOrRespond(TabletReplicaLookupIf* tablet_manager,
+ const string& tablet_id,
+ RespClass* resp,
+ rpc::RpcContext* context,
+ scoped_refptr<TabletReplica>* replica) {
+ if (PREDICT_FALSE(!tablet_manager->GetTabletReplica(tablet_id, replica).ok())) {
SetupErrorAndRespond(resp->mutable_error(),
Status::NotFound("Tablet not found"),
TabletServerErrorPB::TABLET_NOT_FOUND, context);
@@ -165,12 +165,12 @@ bool LookupTabletPeerOrRespond(TabletPeerLookupIf* tablet_manager,
}
// Check RUNNING state.
- tablet::TabletStatePB state = (*peer)->state();
+ tablet::TabletStatePB state = (*replica)->state();
if (PREDICT_FALSE(state != tablet::RUNNING)) {
Status s = Status::IllegalState("Tablet not RUNNING",
tablet::TabletStatePB_Name(state));
if (state == tablet::FAILED) {
- s = s.CloneAndAppend((*peer)->error().ToString());
+ s = s.CloneAndAppend((*replica)->error().ToString());
}
SetupErrorAndRespond(resp->mutable_error(), s,
TabletServerErrorPB::TABLET_NOT_RUNNING, context);
@@ -180,7 +180,7 @@ bool LookupTabletPeerOrRespond(TabletPeerLookupIf* tablet_manager,
}
template<class ReqClass, class RespClass>
-bool CheckUuidMatchOrRespond(TabletPeerLookupIf* tablet_manager,
+bool CheckUuidMatchOrRespond(TabletReplicaLookupIf* tablet_manager,
const char* method_name,
const ReqClass* req,
RespClass* resp,
@@ -211,11 +211,11 @@ bool CheckUuidMatchOrRespond(TabletPeerLookupIf* tablet_manager,
}
template<class RespClass>
-bool GetConsensusOrRespond(const scoped_refptr<TabletPeer>& tablet_peer,
+bool GetConsensusOrRespond(const scoped_refptr<TabletReplica>& replica,
RespClass* resp,
rpc::RpcContext* context,
scoped_refptr<Consensus>* consensus) {
- *consensus = tablet_peer->shared_consensus();
+ *consensus = replica->shared_consensus();
if (!*consensus) {
Status s = Status::ServiceUnavailable("Consensus unavailable. Tablet not running");
SetupErrorAndRespond(resp->mutable_error(), s,
@@ -225,10 +225,10 @@ bool GetConsensusOrRespond(const scoped_refptr<TabletPeer>& tablet_peer,
return true;
}
-Status GetTabletRef(const scoped_refptr<TabletPeer>& tablet_peer,
+Status GetTabletRef(const scoped_refptr<TabletReplica>& replica,
shared_ptr<Tablet>* tablet,
TabletServerErrorPB::Code* error_code) {
- *DCHECK_NOTNULL(tablet) = tablet_peer->shared_tablet();
+ *DCHECK_NOTNULL(tablet) = replica->shared_tablet();
if (PREDICT_FALSE(!*tablet)) {
*error_code = TabletServerErrorPB::TABLET_NOT_RUNNING;
return Status::IllegalState("Tablet is not running");
@@ -573,13 +573,13 @@ void TabletServiceAdminImpl::AlterSchema(const AlterSchemaRequestPB* req,
}
DVLOG(3) << "Received Alter Schema RPC: " << SecureDebugString(*req);
- scoped_refptr<TabletPeer> tablet_peer;
- if (!LookupTabletPeerOrRespond(server_->tablet_manager(), req->tablet_id(), resp, context,
- &tablet_peer)) {
+ scoped_refptr<TabletReplica> replica;
+ if (!LookupTabletReplicaOrRespond(server_->tablet_manager(), req->tablet_id(), resp, context,
+ &replica)) {
return;
}
- uint32_t schema_version = tablet_peer->tablet_metadata()->schema_version();
+ uint32_t schema_version = replica->tablet_metadata()->schema_version();
// If the schema was already applied, respond as succeded
if (schema_version == req->schema_version()) {
@@ -593,13 +593,13 @@ void TabletServiceAdminImpl::AlterSchema(const AlterSchemaRequestPB* req,
return;
}
- Schema tablet_schema = tablet_peer->tablet_metadata()->schema();
+ Schema tablet_schema = replica->tablet_metadata()->schema();
if (req_schema.Equals(tablet_schema)) {
context->RespondSuccess();
return;
}
- schema_version = tablet_peer->tablet_metadata()->schema_version();
+ schema_version = replica->tablet_metadata()->schema_version();
if (schema_version == req->schema_version()) {
LOG(ERROR) << "The current schema does not match the request schema."
<< " version=" << schema_version
@@ -622,14 +622,14 @@ void TabletServiceAdminImpl::AlterSchema(const AlterSchemaRequestPB* req,
}
unique_ptr<AlterSchemaTransactionState> tx_state(
- new AlterSchemaTransactionState(tablet_peer.get(), req, resp));
+ new AlterSchemaTransactionState(replica.get(), req, resp));
tx_state->set_completion_callback(gscoped_ptr<TransactionCompletionCallback>(
new RpcTransactionCompletionCallback<AlterSchemaResponsePB>(context,
resp)));
// Submit the alter schema op. The RPC will be responded to asynchronously.
- Status s = tablet_peer->SubmitAlterSchema(std::move(tx_state));
+ Status s = replica->SubmitAlterSchema(std::move(tx_state));
if (PREDICT_FALSE(!s.ok())) {
SetupErrorAndRespond(resp->mutable_error(), s,
TabletServerErrorPB::UNKNOWN_ERROR,
@@ -739,15 +739,15 @@ void TabletServiceImpl::Write(const WriteRequestPB* req,
"tablet_id", req->tablet_id());
DVLOG(3) << "Received Write RPC: " << SecureDebugString(*req);
- scoped_refptr<TabletPeer> tablet_peer;
- if (!LookupTabletPeerOrRespond(server_->tablet_manager(), req->tablet_id(), resp, context,
- &tablet_peer)) {
+ scoped_refptr<TabletReplica> replica;
+ if (!LookupTabletReplicaOrRespond(server_->tablet_manager(), req->tablet_id(), resp, context,
+ &replica)) {
return;
}
shared_ptr<Tablet> tablet;
TabletServerErrorPB::Code error_code;
- Status s = GetTabletRef(tablet_peer, &tablet, &error_code);
+ Status s = GetTabletRef(replica, &tablet, &error_code);
if (PREDICT_FALSE(!s.ok())) {
SetupErrorAndRespond(resp->mutable_error(), s, error_code, context);
return;
@@ -792,7 +792,7 @@ void TabletServiceImpl::Write(const WriteRequestPB* req,
}
unique_ptr<WriteTransactionState> tx_state(new WriteTransactionState(
- tablet_peer.get(),
+ replica.get(),
req,
context->AreResultsTracked() ? context->request_id() : nullptr,
resp));
@@ -815,7 +815,7 @@ void TabletServiceImpl::Write(const WriteRequestPB* req,
resp)));
// Submit the write. The RPC will be responded to asynchronously.
- s = tablet_peer->SubmitWrite(std::move(tx_state));
+ s = replica->SubmitWrite(std::move(tx_state));
// Check that we could submit the write
if (PREDICT_FALSE(!s.ok())) {
@@ -826,7 +826,7 @@ void TabletServiceImpl::Write(const WriteRequestPB* req,
}
ConsensusServiceImpl::ConsensusServiceImpl(ServerBase* server,
- TabletPeerLookupIf* tablet_manager)
+ TabletReplicaLookupIf* tablet_manager)
: ConsensusServiceIf(server->metric_entity(), server->result_tracker()),
server_(server),
tablet_manager_(tablet_manager) {
@@ -848,16 +848,16 @@ void ConsensusServiceImpl::UpdateConsensus(const ConsensusRequestPB* req,
if (!CheckUuidMatchOrRespond(tablet_manager_, "UpdateConsensus", req, resp, context)) {
return;
}
- scoped_refptr<TabletPeer> tablet_peer;
- if (!LookupTabletPeerOrRespond(tablet_manager_, req->tablet_id(), resp, context, &tablet_peer)) {
+ scoped_refptr<TabletReplica> replica;
+ if (!LookupTabletReplicaOrRespond(tablet_manager_, req->tablet_id(), resp, context, &replica)) {
return;
}
- tablet_peer->permanent_uuid();
+ replica->permanent_uuid();
- // Submit the update directly to the TabletPeer's Consensus instance.
+ // Submit the update directly to the TabletReplica's Consensus instance.
scoped_refptr<Consensus> consensus;
- if (!GetConsensusOrRespond(tablet_peer, resp, context, &consensus)) return;
+ if (!GetConsensusOrRespond(replica, resp, context, &consensus)) return;
Status s = consensus->Update(req, resp);
if (PREDICT_FALSE(!s.ok())) {
// Clear the response first, since a partially-filled response could
@@ -880,14 +880,14 @@ void ConsensusServiceImpl::RequestConsensusVote(const VoteRequestPB* req,
if (!CheckUuidMatchOrRespond(tablet_manager_, "RequestConsensusVote", req, resp, context)) {
return;
}
- scoped_refptr<TabletPeer> tablet_peer;
- if (!LookupTabletPeerOrRespond(tablet_manager_, req->tablet_id(), resp, context, &tablet_peer)) {
+ scoped_refptr<TabletReplica> replica;
+ if (!LookupTabletReplicaOrRespond(tablet_manager_, req->tablet_id(), resp, context, &replica)) {
return;
}
// Submit the vote request directly to the consensus instance.
scoped_refptr<Consensus> consensus;
- if (!GetConsensusOrRespond(tablet_peer, resp, context, &consensus)) return;
+ if (!GetConsensusOrRespond(replica, resp, context, &consensus)) return;
Status s = consensus->RequestVote(req, resp);
if (PREDICT_FALSE(!s.ok())) {
SetupErrorAndRespond(resp->mutable_error(), s,
@@ -905,14 +905,14 @@ void ConsensusServiceImpl::ChangeConfig(const ChangeConfigRequestPB* req,
if (!CheckUuidMatchOrRespond(tablet_manager_, "ChangeConfig", req, resp, context)) {
return;
}
- scoped_refptr<TabletPeer> tablet_peer;
- if (!LookupTabletPeerOrRespond(tablet_manager_, req->tablet_id(), resp, context,
- &tablet_peer)) {
+ scoped_refptr<TabletReplica> replica;
+ if (!LookupTabletReplicaOrRespond(tablet_manager_, req->tablet_id(), resp, context,
+ &replica)) {
return;
}
scoped_refptr<Consensus> consensus;
- if (!GetConsensusOrRespond(tablet_peer, resp, context, &consensus)) return;
+ if (!GetConsensusOrRespond(replica, resp, context, &consensus)) return;
boost::optional<TabletServerErrorPB::Code> error_code;
Status s = consensus->ChangeConfig(*req, BindHandleResponse(req, resp, context), &error_code);
if (PREDICT_FALSE(!s.ok())) {
@@ -929,14 +929,14 @@ void ConsensusServiceImpl::UnsafeChangeConfig(const UnsafeChangeConfigRequestPB*
if (!CheckUuidMatchOrRespond(tablet_manager_, "UnsafeChangeConfig", req, resp, context)) {
return;
}
- scoped_refptr<TabletPeer> tablet_peer;
- if (!LookupTabletPeerOrRespond(tablet_manager_, req->tablet_id(), resp, context,
- &tablet_peer)) {
+ scoped_refptr<TabletReplica> replica;
+ if (!LookupTabletReplicaOrRespond(tablet_manager_, req->tablet_id(), resp, context,
+ &replica)) {
return;
}
scoped_refptr<Consensus> consensus;
- if (!GetConsensusOrRespond(tablet_peer, resp, context, &consensus)) return;
+ if (!GetConsensusOrRespond(replica, resp, context, &consensus)) return;
TabletServerErrorPB::Code error_code;
Status s = consensus->UnsafeChangeConfig(*req, &error_code);
if (PREDICT_FALSE(!s.ok())) {
@@ -961,13 +961,13 @@ void ConsensusServiceImpl::RunLeaderElection(const RunLeaderElectionRequestPB* r
if (!CheckUuidMatchOrRespond(tablet_manager_, "RunLeaderElection", req, resp, context)) {
return;
}
- scoped_refptr<TabletPeer> tablet_peer;
- if (!LookupTabletPeerOrRespond(tablet_manager_, req->tablet_id(), resp, context, &tablet_peer)) {
+ scoped_refptr<TabletReplica> replica;
+ if (!LookupTabletReplicaOrRespond(tablet_manager_, req->tablet_id(), resp, context, &replica)) {
return;
}
scoped_refptr<Consensus> consensus;
- if (!GetConsensusOrRespond(tablet_peer, resp, context, &consensus)) return;
+ if (!GetConsensusOrRespond(replica, resp, context, &consensus)) return;
Status s = consensus->StartElection(
consensus::Consensus::ELECT_EVEN_IF_LEADER_IS_ALIVE,
consensus::Consensus::EXTERNAL_REQUEST);
@@ -987,13 +987,13 @@ void ConsensusServiceImpl::LeaderStepDown(const LeaderStepDownRequestPB* req,
if (!CheckUuidMatchOrRespond(tablet_manager_, "LeaderStepDown", req, resp, context)) {
return;
}
- scoped_refptr<TabletPeer> tablet_peer;
- if (!LookupTabletPeerOrRespond(tablet_manager_, req->tablet_id(), resp, context, &tablet_peer)) {
+ scoped_refptr<TabletReplica> replica;
+ if (!LookupTabletReplicaOrRespond(tablet_manager_, req->tablet_id(), resp, context, &replica)) {
return;
}
scoped_refptr<Consensus> consensus;
- if (!GetConsensusOrRespond(tablet_peer, resp, context, &consensus)) return;
+ if (!GetConsensusOrRespond(replica, resp, context, &consensus)) return;
Status s = consensus->StepDown(resp);
if (PREDICT_FALSE(!s.ok())) {
SetupErrorAndRespond(resp->mutable_error(), s,
@@ -1011,19 +1011,19 @@ void ConsensusServiceImpl::GetLastOpId(const consensus::GetLastOpIdRequestPB *re
if (!CheckUuidMatchOrRespond(tablet_manager_, "GetLastOpId", req, resp, context)) {
return;
}
- scoped_refptr<TabletPeer> tablet_peer;
- if (!LookupTabletPeerOrRespond(tablet_manager_, req->tablet_id(), resp, context, &tablet_peer)) {
+ scoped_refptr<TabletReplica> replica;
+ if (!LookupTabletReplicaOrRespond(tablet_manager_, req->tablet_id(), resp, context, &replica)) {
return;
}
- if (tablet_peer->state() != tablet::RUNNING) {
+ if (replica->state() != tablet::RUNNING) {
SetupErrorAndRespond(resp->mutable_error(),
- Status::ServiceUnavailable("Tablet Peer not in RUNNING state"),
+ Status::ServiceUnavailable("TabletReplica not in RUNNING state"),
TabletServerErrorPB::TABLET_NOT_RUNNING, context);
return;
}
scoped_refptr<Consensus> consensus;
- if (!GetConsensusOrRespond(tablet_peer, resp, context, &consensus)) return;
+ if (!GetConsensusOrRespond(replica, resp, context, &consensus)) return;
if (PREDICT_FALSE(req->opid_type() == consensus::UNKNOWN_OPID_TYPE)) {
HandleUnknownError(Status::InvalidArgument("Invalid opid_type specified to GetLastOpId()"),
resp, context);
@@ -1046,13 +1046,13 @@ void ConsensusServiceImpl::GetConsensusState(const consensus::GetConsensusStateR
if (!CheckUuidMatchOrRespond(tablet_manager_, "GetConsensusState", req, resp, context)) {
return;
}
- scoped_refptr<TabletPeer> tablet_peer;
- if (!LookupTabletPeerOrRespond(tablet_manager_, req->tablet_id(), resp, context, &tablet_peer)) {
+ scoped_refptr<TabletReplica> replica;
+ if (!LookupTabletReplicaOrRespond(tablet_manager_, req->tablet_id(), resp, context, &replica)) {
return;
}
scoped_refptr<Consensus> consensus;
- if (!GetConsensusOrRespond(tablet_peer, resp, context, &consensus)) return;
+ if (!GetConsensusOrRespond(replica, resp, context, &consensus)) return;
ConsensusConfigType type = req->type();
if (PREDICT_FALSE(type != CONSENSUS_CONFIG_ACTIVE && type != CONSENSUS_CONFIG_COMMITTED)) {
HandleUnknownError(
@@ -1128,14 +1128,14 @@ void TabletServiceImpl::Scan(const ScanRequestPB* req,
TabletServerErrorPB::Code error_code = TabletServerErrorPB::UNKNOWN_ERROR;
if (req->has_new_scan_request()) {
const NewScanRequestPB& scan_pb = req->new_scan_request();
- scoped_refptr<TabletPeer> tablet_peer;
- if (!LookupTabletPeerOrRespond(server_->tablet_manager(), scan_pb.tablet_id(), resp, context,
- &tablet_peer)) {
+ scoped_refptr<TabletReplica> replica;
+ if (!LookupTabletReplicaOrRespond(server_->tablet_manager(), scan_pb.tablet_id(), resp, context,
+ &replica)) {
return;
}
string scanner_id;
Timestamp scan_timestamp;
- Status s = HandleNewScanRequest(tablet_peer.get(), req, context,
+ Status s = HandleNewScanRequest(replica.get(), req, context,
&collector, &scanner_id, &scan_timestamp, &has_more_results,
&error_code);
if (PREDICT_FALSE(!s.ok())) {
@@ -1197,17 +1197,17 @@ void TabletServiceImpl::Scan(const ScanRequestPB* req,
void TabletServiceImpl::ListTablets(const ListTabletsRequestPB* req,
ListTabletsResponsePB* resp,
rpc::RpcContext* context) {
- vector<scoped_refptr<TabletPeer> > peers;
- server_->tablet_manager()->GetTabletPeers(&peers);
- RepeatedPtrField<StatusAndSchemaPB>* peer_status = resp->mutable_status_and_schema();
- for (const scoped_refptr<TabletPeer>& peer : peers) {
- StatusAndSchemaPB* status = peer_status->Add();
- peer->GetTabletStatusPB(status->mutable_tablet_status());
+ vector<scoped_refptr<TabletReplica>> replicas;
+ server_->tablet_manager()->GetTabletReplicas(&replicas);
+ RepeatedPtrField<StatusAndSchemaPB>* replica_status = resp->mutable_status_and_schema();
+ for (const scoped_refptr<TabletReplica>& replica : replicas) {
+ StatusAndSchemaPB* status = replica_status->Add();
+ replica->GetTabletStatusPB(status->mutable_tablet_status());
if (req->need_schema_info()) {
- CHECK_OK(SchemaToPB(peer->tablet_metadata()->schema(),
+ CHECK_OK(SchemaToPB(replica->tablet_metadata()->schema(),
status->mutable_schema()));
- peer->tablet_metadata()->partition_schema().ToPB(status->mutable_partition_schema());
+ replica->tablet_metadata()->partition_schema().ToPB(status->mutable_partition_schema());
}
}
context->RespondSuccess();
@@ -1239,15 +1239,15 @@ void TabletServiceImpl::Checksum(const ChecksumRequestPB* req,
if (req->has_new_request()) {
scan_req.mutable_new_scan_request()->CopyFrom(req->new_request());
const NewScanRequestPB& new_req = req->new_request();
- scoped_refptr<TabletPeer> tablet_peer;
- if (!LookupTabletPeerOrRespond(server_->tablet_manager(), new_req.tablet_id(), resp, context,
- &tablet_peer)) {
+ scoped_refptr<TabletReplica> replica;
+ if (!LookupTabletReplicaOrRespond(server_->tablet_manager(), new_req.tablet_id(), resp, context,
+ &replica)) {
return;
}
string scanner_id;
Timestamp snap_timestamp;
- Status s = HandleNewScanRequest(tablet_peer.get(), &scan_req, context,
+ Status s = HandleNewScanRequest(replica.get(), &scan_req, context,
&collector, &scanner_id, &snap_timestamp, &has_more,
&error_code);
if (PREDICT_FALSE(!s.ok())) {
@@ -1478,7 +1478,7 @@ Status VerifyNotAncientHistory(Tablet* tablet, ReadMode read_mode, Timestamp tim
} // anonymous namespace
// Start a new scan.
-Status TabletServiceImpl::HandleNewScanRequest(TabletPeer* tablet_peer,
+Status TabletServiceImpl::HandleNewScanRequest(TabletReplica* replica,
const ScanRequestPB* req,
const RpcContext* rpc_context,
ScanResultCollector* result_collector,
@@ -1493,10 +1493,10 @@ Status TabletServiceImpl::HandleNewScanRequest(TabletPeer* tablet_peer,
TRACE_EVENT1("tserver", "TabletServiceImpl::HandleNewScanRequest",
"tablet_id", scan_pb.tablet_id());
- const Schema& tablet_schema = tablet_peer->tablet_metadata()->schema();
+ const Schema& tablet_schema = replica->tablet_metadata()->schema();
SharedScanner scanner;
- server_->scanner_manager()->NewScanner(tablet_peer,
+ server_->scanner_manager()->NewScanner(replica,
rpc_context->requestor_string(),
scan_pb.row_format_flags(),
&scanner);
@@ -1571,7 +1571,7 @@ Status TabletServiceImpl::HandleNewScanRequest(TabletPeer* tablet_peer,
TabletServerErrorPB::Code tmp_error_code = TabletServerErrorPB::MISMATCHED_SCHEMA;
shared_ptr<Tablet> tablet;
- RETURN_NOT_OK(GetTabletRef(tablet_peer, &tablet, error_code));
+ RETURN_NOT_OK(GetTabletRef(replica, &tablet, error_code));
{
TRACE("Creating iterator");
TRACE_EVENT0("tserver", "Create iterator");
@@ -1587,7 +1587,7 @@ Status TabletServiceImpl::HandleNewScanRequest(TabletPeer* tablet_peer,
break;
}
case READ_AT_SNAPSHOT: {
- s = HandleScanAtSnapshot(scan_pb, rpc_context, projection, tablet_peer,
+ s = HandleScanAtSnapshot(scan_pb, rpc_context, projection, replica,
&iter, snap_timestamp);
// If we got a Status::ServiceUnavailable() from HandleScanAtSnapshot() it might
// mean we're just behind so let the client try again.
@@ -1790,10 +1790,10 @@ Status TabletServiceImpl::HandleContinueScanRequest(const ScanRequestPB* req,
}
}
- scoped_refptr<TabletPeer> tablet_peer = scanner->tablet_peer();
+ scoped_refptr<TabletReplica> replica = scanner->tablet_replica();
shared_ptr<Tablet> tablet;
TabletServerErrorPB::Code tablet_ref_error_code;
- const Status s = GetTabletRef(tablet_peer, &tablet, &tablet_ref_error_code);
+ const Status s = GetTabletRef(replica, &tablet, &tablet_ref_error_code);
// If the tablet is not running, but the scan operation in progress
// has reached this point, the tablet server has the necessary data to
// send in response for the scan continuation request.
@@ -1864,7 +1864,7 @@ MonoTime ClampScanDeadlineForWait(const MonoTime& deadline, bool* was_clamped) {
Status TabletServiceImpl::HandleScanAtSnapshot(const NewScanRequestPB& scan_pb,
const RpcContext* rpc_context,
const Schema& projection,
- TabletPeer* tablet_peer,
+ TabletReplica* replica,
gscoped_ptr<RowwiseIterator>* iter,
Timestamp* snap_timestamp) {
// If the client sent a timestamp update our clock with it.
@@ -1910,13 +1910,13 @@ Status TabletServiceImpl::HandleScanAtSnapshot(const NewScanRequestPB& scan_pb,
// Before we wait on anything check that the timestamp is after the AHM.
// This is not the final check. We'll check this again after the iterators are open but
// there is no point in waiting if we can't actually scan afterwards.
- RETURN_NOT_OK(VerifyNotAncientHistory(tablet_peer->tablet(),
+ RETURN_NOT_OK(VerifyNotAncientHistory(replica->tablet(),
ReadMode::READ_AT_SNAPSHOT,
tmp_snap_timestamp));
tablet::MvccSnapshot snap;
- Tablet* tablet = tablet_peer->tablet();
- scoped_refptr<consensus::TimeManager> time_manager = tablet_peer->time_manager();
+ Tablet* tablet = replica->tablet();
+ scoped_refptr<consensus::TimeManager> time_manager = replica->time_manager();
tablet::MvccManager* mvcc_manager = tablet->mvcc_manager();
// Reduce the client's deadline by a few msecs to allow for overhead.
[4/5] kudu git commit: Rename TabletPeer to TabletReplica
Posted by mp...@apache.org.
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/tablet_peer-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet_peer-test.cc b/src/kudu/tablet/tablet_peer-test.cc
deleted file mode 100644
index 95c7d0c..0000000
--- a/src/kudu/tablet/tablet_peer-test.cc
+++ /dev/null
@@ -1,564 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#include <glog/logging.h>
-#include <gtest/gtest.h>
-
-#include "kudu/common/partial_row.h"
-#include "kudu/common/timestamp.h"
-#include "kudu/common/wire_protocol.h"
-#include "kudu/common/wire_protocol-test-util.h"
-#include "kudu/consensus/consensus_meta.h"
-#include "kudu/consensus/log.h"
-#include "kudu/consensus/log_reader.h"
-#include "kudu/consensus/log_util.h"
-#include "kudu/consensus/opid_util.h"
-#include "kudu/gutil/gscoped_ptr.h"
-#include "kudu/gutil/macros.h"
-#include "kudu/rpc/messenger.h"
-#include "kudu/server/clock.h"
-#include "kudu/server/logical_clock.h"
-#include "kudu/tablet/transactions/transaction.h"
-#include "kudu/tablet/transactions/transaction_driver.h"
-#include "kudu/tablet/transactions/write_transaction.h"
-#include "kudu/tablet/tablet_peer.h"
-#include "kudu/tablet/tablet_peer_mm_ops.h"
-#include "kudu/tablet/tablet-test-util.h"
-#include "kudu/tserver/tserver.pb.h"
-#include "kudu/util/maintenance_manager.h"
-#include "kudu/util/metrics.h"
-#include "kudu/util/pb_util.h"
-#include "kudu/util/test_macros.h"
-#include "kudu/util/test_util.h"
-#include "kudu/util/threadpool.h"
-
-METRIC_DECLARE_entity(tablet);
-
-DECLARE_int32(flush_threshold_mb);
-
-namespace kudu {
-namespace tablet {
-
-using consensus::CommitMsg;
-using consensus::Consensus;
-using consensus::ConsensusBootstrapInfo;
-using consensus::ConsensusMetadata;
-using consensus::MakeOpId;
-using consensus::MinimumOpId;
-using consensus::OpId;
-using consensus::OpIdEquals;
-using consensus::RaftPeerPB;
-using consensus::WRITE_OP;
-using log::Log;
-using log::LogAnchorRegistry;
-using log::LogOptions;
-using rpc::Messenger;
-using server::Clock;
-using server::LogicalClock;
-using std::shared_ptr;
-using std::string;
-using std::unique_ptr;
-using strings::Substitute;
-using tserver::WriteRequestPB;
-using tserver::WriteResponsePB;
-
-static Schema GetTestSchema() {
- return Schema({ ColumnSchema("key", INT32) }, 1);
-}
-
-class TabletPeerTest : public KuduTabletTest {
- public:
- TabletPeerTest()
- : KuduTabletTest(GetTestSchema()),
- insert_counter_(0),
- delete_counter_(0) {
- }
-
- virtual void SetUp() OVERRIDE {
- KuduTabletTest::SetUp();
-
- ASSERT_OK(ThreadPoolBuilder("apply").Build(&apply_pool_));
-
- rpc::MessengerBuilder builder(CURRENT_TEST_NAME());
- ASSERT_OK(builder.Build(&messenger_));
-
- metric_entity_ = METRIC_ENTITY_tablet.Instantiate(&metric_registry_, "test-tablet");
-
- RaftPeerPB config_peer;
- config_peer.set_permanent_uuid(tablet()->metadata()->fs_manager()->uuid());
- config_peer.mutable_last_known_addr()->set_host("0.0.0.0");
- config_peer.mutable_last_known_addr()->set_port(0);
- config_peer.set_member_type(RaftPeerPB::VOTER);
-
- // "Bootstrap" and start the TabletPeer.
- tablet_peer_.reset(
- new TabletPeer(make_scoped_refptr(tablet()->metadata()),
- config_peer,
- apply_pool_.get(),
- Bind(&TabletPeerTest::TabletPeerStateChangedCallback,
- Unretained(this),
- tablet()->tablet_id())));
-
- // Make TabletPeer use the same LogAnchorRegistry as the Tablet created by the harness.
- // TODO: Refactor TabletHarness to allow taking a LogAnchorRegistry, while also providing
- // TabletMetadata for consumption by TabletPeer before Tablet is instantiated.
- tablet_peer_->log_anchor_registry_ = tablet()->log_anchor_registry_;
-
- RaftConfigPB config;
- config.add_peers()->CopyFrom(config_peer);
- config.set_opid_index(consensus::kInvalidOpIdIndex);
-
- unique_ptr<ConsensusMetadata> cmeta;
- ASSERT_OK(ConsensusMetadata::Create(tablet()->metadata()->fs_manager(),
- tablet()->tablet_id(),
- tablet()->metadata()->fs_manager()->uuid(),
- config,
- consensus::kMinimumTerm, &cmeta));
-
- scoped_refptr<Log> log;
- ASSERT_OK(Log::Open(LogOptions(), fs_manager(), tablet()->tablet_id(),
- *tablet()->schema(), tablet()->metadata()->schema_version(),
- metric_entity_.get(), &log));
-
- tablet_peer_->SetBootstrapping();
- ASSERT_OK(tablet_peer_->Init(tablet(),
- clock(),
- messenger_,
- scoped_refptr<rpc::ResultTracker>(),
- log,
- metric_entity_));
- }
-
- Status StartPeer(const ConsensusBootstrapInfo& info) {
- RETURN_NOT_OK(tablet_peer_->Start(info));
- RETURN_NOT_OK(tablet_peer_->consensus()->WaitUntilLeaderForTests(MonoDelta::FromSeconds(10)));
- return Status::OK();
- }
-
- void TabletPeerStateChangedCallback(const string& tablet_id, const string& reason) {
- LOG(INFO) << "Tablet peer state changed for tablet " << tablet_id << ". Reason: " << reason;
- }
-
- virtual void TearDown() OVERRIDE {
- tablet_peer_->Shutdown();
- apply_pool_->Shutdown();
- KuduTabletTest::TearDown();
- }
-
- protected:
- // Generate monotonic sequence of key column integers.
- Status GenerateSequentialInsertRequest(WriteRequestPB* write_req) {
- Schema schema(GetTestSchema());
- write_req->set_tablet_id(tablet()->tablet_id());
- CHECK_OK(SchemaToPB(schema, write_req->mutable_schema()));
-
- KuduPartialRow row(&schema);
- CHECK_OK(row.SetInt32("key", insert_counter_++));
-
- RowOperationsPBEncoder enc(write_req->mutable_row_operations());
- enc.Add(RowOperationsPB::INSERT, row);
- return Status::OK();
- }
-
- // Generate monotonic sequence of deletions, starting with 0.
- // Will assert if you try to delete more rows than you inserted.
- Status GenerateSequentialDeleteRequest(WriteRequestPB* write_req) {
- CHECK_LT(delete_counter_, insert_counter_);
- Schema schema(GetTestSchema());
- write_req->set_tablet_id(tablet()->tablet_id());
- CHECK_OK(SchemaToPB(schema, write_req->mutable_schema()));
-
- KuduPartialRow row(&schema);
- CHECK_OK(row.SetInt32("key", delete_counter_++));
-
- RowOperationsPBEncoder enc(write_req->mutable_row_operations());
- enc.Add(RowOperationsPB::DELETE, row);
- return Status::OK();
- }
-
- Status ExecuteWriteAndRollLog(TabletPeer* tablet_peer, const WriteRequestPB& req) {
- gscoped_ptr<WriteResponsePB> resp(new WriteResponsePB());
- unique_ptr<WriteTransactionState> tx_state(new WriteTransactionState(tablet_peer,
- &req,
- nullptr, // No RequestIdPB
- resp.get()));
-
- CountDownLatch rpc_latch(1);
- tx_state->set_completion_callback(gscoped_ptr<TransactionCompletionCallback>(
- new LatchTransactionCompletionCallback<WriteResponsePB>(&rpc_latch, resp.get())));
-
- CHECK_OK(tablet_peer->SubmitWrite(std::move(tx_state)));
- rpc_latch.Wait();
- CHECK(!resp->has_error())
- << "\nReq:\n" << SecureDebugString(req) << "Resp:\n" << SecureDebugString(*resp);
-
- // Roll the log after each write.
- // Usually the append thread does the roll and no additional sync is required. However in
- // this test the thread that is appending is not the same thread that is rolling the log
- // so we must make sure the Log's queue is flushed before we roll or we might have a race
- // between the appender thread and the thread executing the test.
- CHECK_OK(tablet_peer->log_->WaitUntilAllFlushed());
- CHECK_OK(tablet_peer->log_->AllocateSegmentAndRollOver());
- return Status::OK();
- }
-
- // Execute insert requests and roll log after each one.
- Status ExecuteInsertsAndRollLogs(int num_inserts) {
- for (int i = 0; i < num_inserts; i++) {
- gscoped_ptr<WriteRequestPB> req(new WriteRequestPB());
- RETURN_NOT_OK(GenerateSequentialInsertRequest(req.get()));
- RETURN_NOT_OK(ExecuteWriteAndRollLog(tablet_peer_.get(), *req));
- }
-
- return Status::OK();
- }
-
- // Execute delete requests and roll log after each one.
- Status ExecuteDeletesAndRollLogs(int num_deletes) {
- for (int i = 0; i < num_deletes; i++) {
- gscoped_ptr<WriteRequestPB> req(new WriteRequestPB());
- CHECK_OK(GenerateSequentialDeleteRequest(req.get()));
- CHECK_OK(ExecuteWriteAndRollLog(tablet_peer_.get(), *req));
- }
-
- return Status::OK();
- }
-
- void AssertNoLogAnchors() {
- // Make sure that there are no registered anchors in the registry
- CHECK_EQ(0, tablet_peer_->log_anchor_registry()->GetAnchorCountForTests());
- }
-
- // Assert that the Log GC() anchor is earlier than the latest OpId in the Log.
- void AssertLogAnchorEarlierThanLogLatest() {
- log::RetentionIndexes retention = tablet_peer_->GetRetentionIndexes();
- OpId last_log_opid;
- tablet_peer_->log_->GetLatestEntryOpId(&last_log_opid);
- CHECK_LT(retention.for_durability, last_log_opid.index())
- << "Expected valid log anchor, got earliest opid: " << retention.for_durability
- << " (expected any value earlier than last log id: " << SecureShortDebugString(last_log_opid)
- << ")";
- }
-
- // We disable automatic log GC. Don't leak those changes.
- google::FlagSaver flag_saver_;
-
- int32_t insert_counter_;
- int32_t delete_counter_;
- MetricRegistry metric_registry_;
- scoped_refptr<MetricEntity> metric_entity_;
- shared_ptr<Messenger> messenger_;
- scoped_refptr<TabletPeer> tablet_peer_;
- gscoped_ptr<ThreadPool> apply_pool_;
-};
-
-// A Transaction that waits on the apply_continue latch inside of Apply().
-class DelayedApplyTransaction : public WriteTransaction {
- public:
- DelayedApplyTransaction(CountDownLatch* apply_started,
- CountDownLatch* apply_continue,
- unique_ptr<WriteTransactionState> state)
- : WriteTransaction(std::move(state), consensus::LEADER),
- apply_started_(DCHECK_NOTNULL(apply_started)),
- apply_continue_(DCHECK_NOTNULL(apply_continue)) {
- }
-
- virtual Status Apply(gscoped_ptr<CommitMsg>* commit_msg) OVERRIDE {
- apply_started_->CountDown();
- LOG(INFO) << "Delaying apply...";
- apply_continue_->Wait();
- LOG(INFO) << "Apply proceeding";
- return WriteTransaction::Apply(commit_msg);
- }
-
- private:
- CountDownLatch* apply_started_;
- CountDownLatch* apply_continue_;
- DISALLOW_COPY_AND_ASSIGN(DelayedApplyTransaction);
-};
-
-// Ensure that Log::GC() doesn't delete logs when the MRS has an anchor.
-TEST_F(TabletPeerTest, TestMRSAnchorPreventsLogGC) {
- ConsensusBootstrapInfo info;
- ASSERT_OK(StartPeer(info));
-
- Log* log = tablet_peer_->log_.get();
- int32_t num_gced;
-
- AssertNoLogAnchors();
-
- log::SegmentSequence segments;
- ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
-
- ASSERT_EQ(1, segments.size());
- ASSERT_OK(ExecuteInsertsAndRollLogs(3));
- ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
- ASSERT_EQ(4, segments.size());
-
- AssertLogAnchorEarlierThanLogLatest();
- ASSERT_GT(tablet_peer_->log_anchor_registry()->GetAnchorCountForTests(), 0);
-
- // Ensure nothing gets deleted.
- log::RetentionIndexes retention = tablet_peer_->GetRetentionIndexes();
- ASSERT_OK(log->GC(retention, &num_gced));
- ASSERT_EQ(0, num_gced) << "earliest needed: " << retention.for_durability;
-
- // Flush MRS as needed to ensure that we don't have OpId anchors in the MRS.
- tablet_peer_->tablet()->Flush();
- AssertNoLogAnchors();
-
- // The first two segments should be deleted.
- // The last is anchored due to the commit in the last segment being the last
- // OpId in the log.
- retention = tablet_peer_->GetRetentionIndexes();
- ASSERT_OK(log->GC(retention, &num_gced));
- ASSERT_EQ(2, num_gced) << "earliest needed: " << retention.for_durability;
- ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
- ASSERT_EQ(2, segments.size());
-}
-
-// Ensure that Log::GC() doesn't delete logs when the DMS has an anchor.
-TEST_F(TabletPeerTest, TestDMSAnchorPreventsLogGC) {
- ConsensusBootstrapInfo info;
- ASSERT_OK(StartPeer(info));
-
- Log* log = tablet_peer_->log_.get();
- int32_t num_gced;
-
- AssertNoLogAnchors();
-
- log::SegmentSequence segments;
- ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
-
- ASSERT_EQ(1, segments.size());
- ASSERT_OK(ExecuteInsertsAndRollLogs(2));
- ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
- ASSERT_EQ(3, segments.size());
-
- // Flush MRS & GC log so the next mutation goes into a DMS.
- ASSERT_OK(tablet_peer_->tablet()->Flush());
- log::RetentionIndexes retention = tablet_peer_->GetRetentionIndexes();
- ASSERT_OK(log->GC(retention, &num_gced));
- // We will only GC 1, and have 1 left because the earliest needed OpId falls
- // back to the latest OpId written to the Log if no anchors are set.
- ASSERT_EQ(1, num_gced);
- ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
- ASSERT_EQ(2, segments.size());
- AssertNoLogAnchors();
-
- OpId id;
- log->GetLatestEntryOpId(&id);
- LOG(INFO) << "Before: " << SecureShortDebugString(id);
-
-
- // We currently have no anchors and the last operation in the log is 0.3
- // Before the below was ExecuteDeletesAndRollLogs(1) but that was breaking
- // what I think is a wrong assertion.
- // I.e. since 0.4 is the last operation that we know is in memory 0.4 is the
- // last anchor we expect _and_ it's the last op in the log.
- // Only if we apply two operations is the last anchored operation and the
- // last operation in the log different.
-
- // Execute a mutation.
- ASSERT_OK(ExecuteDeletesAndRollLogs(2));
- AssertLogAnchorEarlierThanLogLatest();
- ASSERT_GT(tablet_peer_->log_anchor_registry()->GetAnchorCountForTests(), 0);
- ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
- ASSERT_EQ(4, segments.size());
-
- // Execute another couple inserts, but Flush it so it doesn't anchor.
- ASSERT_OK(ExecuteInsertsAndRollLogs(2));
- ASSERT_OK(tablet_peer_->tablet()->Flush());
- ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
- ASSERT_EQ(6, segments.size());
-
- // Ensure the delta and last insert remain in the logs, anchored by the delta.
- // Note that this will allow GC of the 2nd insert done above.
- retention = tablet_peer_->GetRetentionIndexes();
- ASSERT_OK(log->GC(retention, &num_gced));
- ASSERT_EQ(1, num_gced);
- ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
- ASSERT_EQ(5, segments.size());
-
- // Flush DMS to release the anchor.
- tablet_peer_->tablet()->FlushBiggestDMS();
-
- // Verify no anchors after Flush().
- AssertNoLogAnchors();
-
- // We should only hang onto one segment due to no anchors.
- // The last log OpId is the commit in the last segment, so it only anchors
- // that segment, not the previous, because it's not the first OpId in the
- // segment.
- retention = tablet_peer_->GetRetentionIndexes();
- ASSERT_OK(log->GC(retention, &num_gced));
- ASSERT_EQ(3, num_gced);
- ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
- ASSERT_EQ(2, segments.size());
-}
-
-// Ensure that Log::GC() doesn't compact logs with OpIds of active transactions.
-TEST_F(TabletPeerTest, TestActiveTransactionPreventsLogGC) {
- ConsensusBootstrapInfo info;
- ASSERT_OK(StartPeer(info));
-
- Log* log = tablet_peer_->log_.get();
- int32_t num_gced;
-
- AssertNoLogAnchors();
-
- log::SegmentSequence segments;
- ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
-
- ASSERT_EQ(1, segments.size());
- ASSERT_OK(ExecuteInsertsAndRollLogs(4));
- ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
- ASSERT_EQ(5, segments.size());
-
- // Flush MRS as needed to ensure that we don't have OpId anchors in the MRS.
- ASSERT_EQ(1, tablet_peer_->log_anchor_registry()->GetAnchorCountForTests());
- tablet_peer_->tablet()->Flush();
-
- // Verify no anchors after Flush().
- AssertNoLogAnchors();
-
- // Now create a long-lived Transaction that hangs during Apply().
- // Allow other transactions to go through. Logs should be populated, but the
- // long-lived Transaction should prevent the log from being deleted since it
- // is in-flight.
- CountDownLatch rpc_latch(1);
- CountDownLatch apply_started(1);
- CountDownLatch apply_continue(1);
- gscoped_ptr<WriteRequestPB> req(new WriteRequestPB());
- gscoped_ptr<WriteResponsePB> resp(new WriteResponsePB());
- {
- // Long-running mutation.
- ASSERT_OK(GenerateSequentialDeleteRequest(req.get()));
- unique_ptr<WriteTransactionState> tx_state(new WriteTransactionState(tablet_peer_.get(),
- req.get(),
- nullptr, // No RequestIdPB
- resp.get()));
-
- tx_state->set_completion_callback(gscoped_ptr<TransactionCompletionCallback>(
- new LatchTransactionCompletionCallback<WriteResponsePB>(&rpc_latch, resp.get())));
-
- gscoped_ptr<DelayedApplyTransaction> transaction(
- new DelayedApplyTransaction(&apply_started,
- &apply_continue,
- std::move(tx_state)));
-
- scoped_refptr<TransactionDriver> driver;
- ASSERT_OK(tablet_peer_->NewLeaderTransactionDriver(transaction.PassAs<Transaction>(),
- &driver));
-
- ASSERT_OK(driver->ExecuteAsync());
- apply_started.Wait();
- ASSERT_TRUE(driver->GetOpId().IsInitialized())
- << "By the time a transaction is applied, it should have an Opid";
- // The apply will hang until we CountDown() the continue latch.
- // Now, roll the log. Below, we execute a few more insertions with rolling.
- ASSERT_OK(log->AllocateSegmentAndRollOver());
- }
-
- ASSERT_EQ(1, tablet_peer_->txn_tracker_.GetNumPendingForTests());
- // The log anchor is currently equal to the latest OpId written to the Log
- // because we are delaying the Commit message with the CountDownLatch.
-
- // GC the first four segments created by the inserts.
- log::RetentionIndexes retention = tablet_peer_->GetRetentionIndexes();
- ASSERT_OK(log->GC(retention, &num_gced));
- ASSERT_EQ(4, num_gced);
- ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
- ASSERT_EQ(2, segments.size());
-
- // We use mutations here, since an MRS Flush() quiesces the tablet, and we
- // want to ensure the only thing "anchoring" is the TransactionTracker.
- ASSERT_OK(ExecuteDeletesAndRollLogs(3));
- ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
- ASSERT_EQ(5, segments.size());
- ASSERT_EQ(1, tablet_peer_->log_anchor_registry()->GetAnchorCountForTests());
- tablet_peer_->tablet()->FlushBiggestDMS();
- ASSERT_EQ(0, tablet_peer_->log_anchor_registry()->GetAnchorCountForTests());
- ASSERT_EQ(1, tablet_peer_->txn_tracker_.GetNumPendingForTests());
-
- AssertLogAnchorEarlierThanLogLatest();
-
- // Try to GC(), nothing should be deleted due to the in-flight transaction.
- retention = tablet_peer_->GetRetentionIndexes();
- ASSERT_OK(log->GC(retention, &num_gced));
- ASSERT_EQ(0, num_gced);
- ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
- ASSERT_EQ(5, segments.size());
-
- // Now we release the transaction and wait for everything to complete.
- // We fully quiesce and flush, which should release all anchors.
- ASSERT_EQ(1, tablet_peer_->txn_tracker_.GetNumPendingForTests());
- apply_continue.CountDown();
- rpc_latch.Wait();
- tablet_peer_->txn_tracker_.WaitForAllToFinish();
- ASSERT_EQ(0, tablet_peer_->txn_tracker_.GetNumPendingForTests());
- tablet_peer_->tablet()->FlushBiggestDMS();
- AssertNoLogAnchors();
-
- // All should be deleted except the two last segments.
- retention = tablet_peer_->GetRetentionIndexes();
- ASSERT_OK(log->GC(retention, &num_gced));
- ASSERT_EQ(3, num_gced);
- ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
- ASSERT_EQ(2, segments.size());
-}
-
-TEST_F(TabletPeerTest, TestGCEmptyLog) {
- ConsensusBootstrapInfo info;
- tablet_peer_->Start(info);
- // We don't wait on consensus on purpose.
- ASSERT_OK(tablet_peer_->RunLogGC());
-}
-
-TEST_F(TabletPeerTest, TestFlushOpsPerfImprovements) {
- FLAGS_flush_threshold_mb = 64;
-
- MaintenanceOpStats stats;
-
- // Just on the threshold and not enough time has passed for a time-based flush.
- stats.set_ram_anchored(64 * 1024 * 1024);
- FlushOpPerfImprovementPolicy::SetPerfImprovementForFlush(&stats, 1);
- ASSERT_EQ(0.0, stats.perf_improvement());
- stats.Clear();
-
- // Just on the threshold and enough time has passed, we'll have a low improvement.
- stats.set_ram_anchored(64 * 1024 * 1024);
- FlushOpPerfImprovementPolicy::SetPerfImprovementForFlush(&stats, 3 * 60 * 1000);
- ASSERT_GT(stats.perf_improvement(), 0.01);
- stats.Clear();
-
- // Way over the threshold, number is much higher than 1.
- stats.set_ram_anchored(128 * 1024 * 1024);
- FlushOpPerfImprovementPolicy::SetPerfImprovementForFlush(&stats, 1);
- ASSERT_LT(1.0, stats.perf_improvement());
- stats.Clear();
-
- // Below the threshold but have been there a long time, closing in to 1.0.
- stats.set_ram_anchored(30 * 1024 * 1024);
- FlushOpPerfImprovementPolicy::SetPerfImprovementForFlush(&stats, 60 * 50 * 1000);
- ASSERT_LT(0.7, stats.perf_improvement());
- ASSERT_GT(1.0, stats.perf_improvement());
- stats.Clear();
-}
-
-} // namespace tablet
-} // namespace kudu
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/tablet_peer.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet_peer.cc b/src/kudu/tablet/tablet_peer.cc
deleted file mode 100644
index d9bddb4..0000000
--- a/src/kudu/tablet/tablet_peer.cc
+++ /dev/null
@@ -1,672 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#include "kudu/tablet/tablet_peer.h"
-
-#include <algorithm>
-#include <gflags/gflags.h>
-#include <memory>
-#include <mutex>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "kudu/consensus/consensus.h"
-#include "kudu/consensus/consensus_meta.h"
-#include "kudu/consensus/log.h"
-#include "kudu/consensus/log_util.h"
-#include "kudu/consensus/opid_util.h"
-#include "kudu/consensus/log_anchor_registry.h"
-#include "kudu/consensus/quorum_util.h"
-#include "kudu/consensus/raft_consensus.h"
-#include "kudu/gutil/mathlimits.h"
-#include "kudu/gutil/stl_util.h"
-#include "kudu/gutil/strings/substitute.h"
-#include "kudu/gutil/sysinfo.h"
-#include "kudu/rpc/messenger.h"
-#include "kudu/rpc/remote_method.h"
-#include "kudu/rpc/rpc_service.h"
-#include "kudu/rpc/service_pool.h"
-#include "kudu/tablet/transactions/transaction_driver.h"
-#include "kudu/tablet/transactions/alter_schema_transaction.h"
-#include "kudu/tablet/transactions/write_transaction.h"
-#include "kudu/tablet/tablet_bootstrap.h"
-#include "kudu/tablet/tablet_metrics.h"
-#include "kudu/tablet/tablet_peer_mm_ops.h"
-#include "kudu/tablet/tablet.pb.h"
-#include "kudu/util/logging.h"
-#include "kudu/util/metrics.h"
-#include "kudu/util/pb_util.h"
-#include "kudu/util/stopwatch.h"
-#include "kudu/util/threadpool.h"
-#include "kudu/util/trace.h"
-
-using std::map;
-using std::shared_ptr;
-using std::unique_ptr;
-
-namespace kudu {
-namespace tablet {
-
-METRIC_DEFINE_histogram(tablet, op_prepare_queue_length, "Operation Prepare Queue Length",
- MetricUnit::kTasks,
- "Number of operations waiting to be prepared within this tablet. "
- "High queue lengths indicate that the server is unable to process "
- "operations as fast as they are being written to the WAL.",
- 10000, 2);
-
-METRIC_DEFINE_histogram(tablet, op_prepare_queue_time, "Operation Prepare Queue Time",
- MetricUnit::kMicroseconds,
- "Time that operations spent waiting in the prepare queue before being "
- "processed. High queue times indicate that the server is unable to "
- "process operations as fast as they are being written to the WAL.",
- 10000000, 2);
-
-METRIC_DEFINE_histogram(tablet, op_prepare_run_time, "Operation Prepare Run Time",
- MetricUnit::kMicroseconds,
- "Time that operations spent being prepared in the tablet. "
- "High values may indicate that the server is under-provisioned or "
- "that operations are experiencing high contention with one another for "
- "locks.",
- 10000000, 2);
-
-using consensus::Consensus;
-using consensus::ConsensusBootstrapInfo;
-using consensus::ConsensusMetadata;
-using consensus::ConsensusOptions;
-using consensus::ConsensusRound;
-using consensus::OpId;
-using consensus::RaftConfigPB;
-using consensus::RaftPeerPB;
-using consensus::RaftConsensus;
-using consensus::TimeManager;
-using consensus::ALTER_SCHEMA_OP;
-using consensus::WRITE_OP;
-using log::Log;
-using log::LogAnchorRegistry;
-using rpc::Messenger;
-using rpc::ResultTracker;
-using strings::Substitute;
-using tserver::TabletServerErrorPB;
-
-// ============================================================================
-// Tablet Peer
-// ============================================================================
-TabletPeer::TabletPeer(const scoped_refptr<TabletMetadata>& meta,
- const consensus::RaftPeerPB& local_peer_pb,
- ThreadPool* apply_pool,
- Callback<void(const std::string& reason)> mark_dirty_clbk)
- : meta_(meta),
- tablet_id_(meta->tablet_id()),
- local_peer_pb_(local_peer_pb),
- state_(NOT_STARTED),
- last_status_("Tablet initializing..."),
- apply_pool_(apply_pool),
- log_anchor_registry_(new LogAnchorRegistry()),
- mark_dirty_clbk_(std::move(mark_dirty_clbk)) {}
-
-TabletPeer::~TabletPeer() {
- std::lock_guard<simple_spinlock> lock(lock_);
- // We should either have called Shutdown(), or we should have never called
- // Init().
- CHECK(!tablet_)
- << "TabletPeer not fully shut down. State: "
- << TabletStatePB_Name(state_);
-}
-
-Status TabletPeer::Init(const shared_ptr<Tablet>& tablet,
- const scoped_refptr<server::Clock>& clock,
- const shared_ptr<Messenger>& messenger,
- const scoped_refptr<ResultTracker>& result_tracker,
- const scoped_refptr<Log>& log,
- const scoped_refptr<MetricEntity>& metric_entity) {
-
- DCHECK(tablet) << "A TabletPeer must be provided with a Tablet";
- DCHECK(log) << "A TabletPeer must be provided with a Log";
-
- RETURN_NOT_OK(ThreadPoolBuilder("prepare").set_max_threads(1).Build(&prepare_pool_));
- prepare_pool_->SetQueueLengthHistogram(
- METRIC_op_prepare_queue_length.Instantiate(metric_entity));
- prepare_pool_->SetQueueTimeMicrosHistogram(
- METRIC_op_prepare_queue_time.Instantiate(metric_entity));
- prepare_pool_->SetRunTimeMicrosHistogram(
- METRIC_op_prepare_run_time.Instantiate(metric_entity));
-
- {
- std::lock_guard<simple_spinlock> lock(lock_);
- CHECK_EQ(BOOTSTRAPPING, state_);
- tablet_ = tablet;
- clock_ = clock;
- messenger_ = messenger;
- log_ = log;
- result_tracker_ = result_tracker;
-
- ConsensusOptions options;
- options.tablet_id = meta_->tablet_id();
-
- TRACE("Creating consensus instance");
-
- unique_ptr<ConsensusMetadata> cmeta;
- RETURN_NOT_OK(ConsensusMetadata::Load(meta_->fs_manager(), tablet_id_,
- meta_->fs_manager()->uuid(), &cmeta));
-
- scoped_refptr<TimeManager> time_manager(new TimeManager(
- clock, tablet_->mvcc_manager()->GetCleanTimestamp()));
-
- consensus_ = RaftConsensus::Create(options,
- std::move(cmeta),
- local_peer_pb_,
- metric_entity,
- time_manager,
- this,
- messenger_,
- log_.get(),
- tablet_->mem_tracker(),
- mark_dirty_clbk_);
- }
-
- if (tablet_->metrics() != nullptr) {
- TRACE("Starting instrumentation");
- txn_tracker_.StartInstrumentation(tablet_->GetMetricEntity());
- }
- txn_tracker_.StartMemoryTracking(tablet_->mem_tracker());
-
- TRACE("TabletPeer::Init() finished");
- VLOG(2) << "T " << tablet_id() << " P " << consensus_->peer_uuid() << ": Peer Initted";
- return Status::OK();
-}
-
-Status TabletPeer::Start(const ConsensusBootstrapInfo& bootstrap_info) {
- std::lock_guard<simple_spinlock> l(state_change_lock_);
- TRACE("Starting consensus");
-
- VLOG(2) << "T " << tablet_id() << " P " << consensus_->peer_uuid() << ": Peer starting";
-
- VLOG(2) << "RaftConfig before starting: " << SecureDebugString(consensus_->CommittedConfig());
-
- RETURN_NOT_OK(consensus_->Start(bootstrap_info));
- {
- std::lock_guard<simple_spinlock> lock(lock_);
- CHECK_EQ(state_, BOOTSTRAPPING);
- state_ = RUNNING;
- }
-
- // Because we changed the tablet state, we need to re-report the tablet to the master.
- mark_dirty_clbk_.Run("Started TabletPeer");
-
- return Status::OK();
-}
-
-const consensus::RaftConfigPB TabletPeer::RaftConfig() const {
- CHECK(consensus_) << "consensus is null";
- return consensus_->CommittedConfig();
-}
-
-void TabletPeer::Shutdown() {
-
- LOG(INFO) << "Initiating TabletPeer shutdown for tablet: " << tablet_id_;
-
- {
- std::unique_lock<simple_spinlock> lock(lock_);
- if (state_ == QUIESCING || state_ == SHUTDOWN) {
- lock.unlock();
- WaitUntilShutdown();
- return;
- }
- state_ = QUIESCING;
- }
-
- std::lock_guard<simple_spinlock> l(state_change_lock_);
- // Even though Tablet::Shutdown() also unregisters its ops, we have to do it here
- // to ensure that any currently running operation finishes before we proceed with
- // the rest of the shutdown sequence. In particular, a maintenance operation could
- // indirectly end up calling into the log, which we are about to shut down.
- if (tablet_) tablet_->UnregisterMaintenanceOps();
- UnregisterMaintenanceOps();
-
- if (consensus_) consensus_->Shutdown();
-
- // TODO: KUDU-183: Keep track of the pending tasks and send an "abort" message.
- LOG_SLOW_EXECUTION(WARNING, 1000,
- Substitute("TabletPeer: tablet $0: Waiting for Transactions to complete", tablet_id())) {
- txn_tracker_.WaitForAllToFinish();
- }
-
- if (prepare_pool_) {
- prepare_pool_->Shutdown();
- }
-
- if (log_) {
- WARN_NOT_OK(log_->Close(), "Error closing the Log.");
- }
-
- if (VLOG_IS_ON(1)) {
- VLOG(1) << "TabletPeer: tablet " << tablet_id() << " shut down!";
- }
-
- if (tablet_) {
- tablet_->Shutdown();
- }
-
- // Only mark the peer as SHUTDOWN when all other components have shut down.
- {
- std::lock_guard<simple_spinlock> lock(lock_);
- // Release mem tracker resources.
- consensus_.reset();
- tablet_.reset();
- state_ = SHUTDOWN;
- }
-}
-
-void TabletPeer::WaitUntilShutdown() {
- while (true) {
- {
- std::lock_guard<simple_spinlock> lock(lock_);
- if (state_ == SHUTDOWN) {
- return;
- }
- }
- SleepFor(MonoDelta::FromMilliseconds(10));
- }
-}
-
-Status TabletPeer::CheckRunning() const {
- {
- std::lock_guard<simple_spinlock> lock(lock_);
- if (state_ != RUNNING) {
- return Status::IllegalState(Substitute("The tablet is not in a running state: $0",
- TabletStatePB_Name(state_)));
- }
- }
- return Status::OK();
-}
-
-Status TabletPeer::WaitUntilConsensusRunning(const MonoDelta& timeout) {
- MonoTime start(MonoTime::Now());
-
- int backoff_exp = 0;
- const int kMaxBackoffExp = 8;
- while (true) {
- bool has_consensus = false;
- TabletStatePB cached_state;
- {
- std::lock_guard<simple_spinlock> lock(lock_);
- cached_state = state_;
- if (consensus_) {
- has_consensus = true; // consensus_ is a set-once object.
- }
- }
- if (cached_state == QUIESCING || cached_state == SHUTDOWN) {
- return Status::IllegalState(
- Substitute("The tablet is already shutting down or shutdown. State: $0",
- TabletStatePB_Name(cached_state)));
- }
- if (cached_state == RUNNING && has_consensus && consensus_->IsRunning()) {
- break;
- }
- MonoTime now(MonoTime::Now());
- MonoDelta elapsed(now - start);
- if (elapsed > timeout) {
- return Status::TimedOut(Substitute("Consensus is not running after waiting for $0. State; $1",
- elapsed.ToString(), TabletStatePB_Name(cached_state)));
- }
- SleepFor(MonoDelta::FromMilliseconds(1 << backoff_exp));
- backoff_exp = std::min(backoff_exp + 1, kMaxBackoffExp);
- }
- return Status::OK();
-}
-
-Status TabletPeer::SubmitWrite(unique_ptr<WriteTransactionState> state) {
- RETURN_NOT_OK(CheckRunning());
-
- state->SetResultTracker(result_tracker_);
- gscoped_ptr<WriteTransaction> transaction(new WriteTransaction(std::move(state),
- consensus::LEADER));
- scoped_refptr<TransactionDriver> driver;
- RETURN_NOT_OK(NewLeaderTransactionDriver(transaction.PassAs<Transaction>(),
- &driver));
- return driver->ExecuteAsync();
-}
-
-Status TabletPeer::SubmitAlterSchema(unique_ptr<AlterSchemaTransactionState> state) {
- RETURN_NOT_OK(CheckRunning());
-
- gscoped_ptr<AlterSchemaTransaction> transaction(
- new AlterSchemaTransaction(std::move(state), consensus::LEADER));
- scoped_refptr<TransactionDriver> driver;
- RETURN_NOT_OK(NewLeaderTransactionDriver(transaction.PassAs<Transaction>(), &driver));
- return driver->ExecuteAsync();
-}
-
-void TabletPeer::GetTabletStatusPB(TabletStatusPB* status_pb_out) const {
- std::lock_guard<simple_spinlock> lock(lock_);
- DCHECK(status_pb_out != nullptr);
- status_pb_out->set_tablet_id(meta_->tablet_id());
- status_pb_out->set_table_name(meta_->table_name());
- status_pb_out->set_last_status(last_status_);
- meta_->partition().ToPB(status_pb_out->mutable_partition());
- status_pb_out->set_state(state_);
- status_pb_out->set_tablet_data_state(meta_->tablet_data_state());
- if (tablet_) {
- status_pb_out->set_estimated_on_disk_size(tablet_->EstimateOnDiskSize());
- }
-}
-
-Status TabletPeer::RunLogGC() {
- if (!CheckRunning().ok()) {
- return Status::OK();
- }
- int32_t num_gced;
- log::RetentionIndexes retention = GetRetentionIndexes();
- Status s = log_->GC(retention, &num_gced);
- if (!s.ok()) {
- s = s.CloneAndPrepend("Unexpected error while running Log GC from TabletPeer");
- LOG(ERROR) << s.ToString();
- }
- return Status::OK();
-}
-
-void TabletPeer::StatusMessage(const std::string& status) {
- std::lock_guard<simple_spinlock> lock(lock_);
- last_status_ = status;
-}
-
-string TabletPeer::last_status() const {
- std::lock_guard<simple_spinlock> lock(lock_);
- return last_status_;
-}
-
-void TabletPeer::SetFailed(const Status& error) {
- std::lock_guard<simple_spinlock> lock(lock_);
- CHECK(!error.ok());
- state_ = FAILED;
- error_ = error;
- last_status_ = error.ToString();
-}
-
-string TabletPeer::HumanReadableState() const {
- std::lock_guard<simple_spinlock> lock(lock_);
- TabletDataState data_state = meta_->tablet_data_state();
- // If failed, any number of things could have gone wrong.
- if (state_ == FAILED) {
- return Substitute("$0 ($1): $2", TabletStatePB_Name(state_),
- TabletDataState_Name(data_state),
- error_.ToString());
- // If it's copying, or tombstoned, that is the important thing
- // to show.
- } else if (data_state != TABLET_DATA_READY) {
- return TabletDataState_Name(data_state);
- }
- // Otherwise, the tablet's data is in a "normal" state, so we just display
- // the runtime state (BOOTSTRAPPING, RUNNING, etc).
- return TabletStatePB_Name(state_);
-}
-
-void TabletPeer::GetInFlightTransactions(Transaction::TraceType trace_type,
- vector<consensus::TransactionStatusPB>* out) const {
- vector<scoped_refptr<TransactionDriver> > pending_transactions;
- txn_tracker_.GetPendingTransactions(&pending_transactions);
- for (const scoped_refptr<TransactionDriver>& driver : pending_transactions) {
- if (driver->state() != nullptr) {
- consensus::TransactionStatusPB status_pb;
- status_pb.mutable_op_id()->CopyFrom(driver->GetOpId());
- switch (driver->tx_type()) {
- case Transaction::WRITE_TXN:
- status_pb.set_tx_type(consensus::WRITE_OP);
- break;
- case Transaction::ALTER_SCHEMA_TXN:
- status_pb.set_tx_type(consensus::ALTER_SCHEMA_OP);
- break;
- }
- status_pb.set_description(driver->ToString());
- int64_t running_for_micros =
- (MonoTime::Now() - driver->start_time()).ToMicroseconds();
- status_pb.set_running_for_micros(running_for_micros);
- if (trace_type == Transaction::TRACE_TXNS) {
- status_pb.set_trace_buffer(driver->trace()->DumpToString());
- }
- out->push_back(status_pb);
- }
- }
-}
-
-log::RetentionIndexes TabletPeer::GetRetentionIndexes() const {
- // Let consensus set a minimum index that should be anchored.
- // This ensures that we:
- // (a) don't GC any operations which are still in flight
- // (b) don't GC any operations that are needed to catch up lagging peers.
- log::RetentionIndexes ret = consensus_->GetRetentionIndexes();
-
- // If we never have written to the log, no need to proceed.
- if (ret.for_durability == 0) return ret;
-
- // Next, we interrogate the anchor registry.
- // Returns OK if minimum known, NotFound if no anchors are registered.
- {
- int64_t min_anchor_index;
- Status s = log_anchor_registry_->GetEarliestRegisteredLogIndex(&min_anchor_index);
- if (PREDICT_FALSE(!s.ok())) {
- DCHECK(s.IsNotFound()) << "Unexpected error calling LogAnchorRegistry: " << s.ToString();
- } else {
- ret.for_durability = std::min(ret.for_durability, min_anchor_index);
- }
- }
-
- // Next, interrogate the TransactionTracker.
- vector<scoped_refptr<TransactionDriver> > pending_transactions;
- txn_tracker_.GetPendingTransactions(&pending_transactions);
- for (const scoped_refptr<TransactionDriver>& driver : pending_transactions) {
- OpId tx_op_id = driver->GetOpId();
- // A transaction which doesn't have an opid hasn't been submitted for replication yet and
- // thus has no need to anchor the log.
- if (tx_op_id.IsInitialized()) {
- ret.for_durability = std::min(ret.for_durability, tx_op_id.index());
- }
- }
-
- return ret;
-}
-
-Status TabletPeer::GetReplaySizeMap(map<int64_t, int64_t>* replay_size_map) const {
- RETURN_NOT_OK(CheckRunning());
- log_->GetReplaySizeMap(replay_size_map);
- return Status::OK();
-}
-
-Status TabletPeer::GetGCableDataSize(int64_t* retention_size) const {
- RETURN_NOT_OK(CheckRunning());
- *retention_size = log_->GetGCableDataSize(GetRetentionIndexes());
- return Status::OK();
-}
-
-Status TabletPeer::StartReplicaTransaction(const scoped_refptr<ConsensusRound>& round) {
- {
- std::lock_guard<simple_spinlock> lock(lock_);
- if (state_ != RUNNING && state_ != BOOTSTRAPPING) {
- return Status::IllegalState(TabletStatePB_Name(state_));
- }
- }
-
- consensus::ReplicateMsg* replicate_msg = round->replicate_msg();
- DCHECK(replicate_msg->has_timestamp());
- gscoped_ptr<Transaction> transaction;
- switch (replicate_msg->op_type()) {
- case WRITE_OP:
- {
- DCHECK(replicate_msg->has_write_request()) << "WRITE_OP replica"
- " transaction must receive a WriteRequestPB";
- unique_ptr<WriteTransactionState> tx_state(
- new WriteTransactionState(
- this,
- &replicate_msg->write_request(),
- replicate_msg->has_request_id() ? &replicate_msg->request_id() : nullptr));
- tx_state->SetResultTracker(result_tracker_);
-
- transaction.reset(new WriteTransaction(std::move(tx_state), consensus::REPLICA));
- break;
- }
- case ALTER_SCHEMA_OP:
- {
- DCHECK(replicate_msg->has_alter_schema_request()) << "ALTER_SCHEMA_OP replica"
- " transaction must receive an AlterSchemaRequestPB";
- unique_ptr<AlterSchemaTransactionState> tx_state(
- new AlterSchemaTransactionState(this, &replicate_msg->alter_schema_request(),
- nullptr));
- transaction.reset(
- new AlterSchemaTransaction(std::move(tx_state), consensus::REPLICA));
- break;
- }
- default:
- LOG(FATAL) << "Unsupported Operation Type";
- }
-
- // TODO(todd) Look at wiring the stuff below on the driver
- TransactionState* state = transaction->state();
- state->set_consensus_round(round);
-
- scoped_refptr<TransactionDriver> driver;
- RETURN_NOT_OK(NewReplicaTransactionDriver(std::move(transaction), &driver));
-
- // Unretained is required to avoid a refcount cycle.
- state->consensus_round()->SetConsensusReplicatedCallback(
- Bind(&TransactionDriver::ReplicationFinished, Unretained(driver.get())));
-
- RETURN_NOT_OK(driver->ExecuteAsync());
- return Status::OK();
-}
-
-Status TabletPeer::NewLeaderTransactionDriver(gscoped_ptr<Transaction> transaction,
- scoped_refptr<TransactionDriver>* driver) {
- scoped_refptr<TransactionDriver> tx_driver = new TransactionDriver(
- &txn_tracker_,
- consensus_.get(),
- log_.get(),
- prepare_pool_.get(),
- apply_pool_,
- &txn_order_verifier_);
- RETURN_NOT_OK(tx_driver->Init(std::move(transaction), consensus::LEADER));
- driver->swap(tx_driver);
-
- return Status::OK();
-}
-
-Status TabletPeer::NewReplicaTransactionDriver(gscoped_ptr<Transaction> transaction,
- scoped_refptr<TransactionDriver>* driver) {
- scoped_refptr<TransactionDriver> tx_driver = new TransactionDriver(
- &txn_tracker_,
- consensus_.get(),
- log_.get(),
- prepare_pool_.get(),
- apply_pool_,
- &txn_order_verifier_);
- RETURN_NOT_OK(tx_driver->Init(std::move(transaction), consensus::REPLICA));
- driver->swap(tx_driver);
-
- return Status::OK();
-}
-
-void TabletPeer::RegisterMaintenanceOps(MaintenanceManager* maint_mgr) {
- // Taking state_change_lock_ ensures that we don't shut down concurrently with
- // this last start-up task.
- std::lock_guard<simple_spinlock> l(state_change_lock_);
-
- if (state() != RUNNING) {
- LOG(WARNING) << "Not registering maintenance operations for " << tablet_
- << ": tablet not in RUNNING state";
- return;
- }
-
- DCHECK(maintenance_ops_.empty());
-
- gscoped_ptr<MaintenanceOp> mrs_flush_op(new FlushMRSOp(this));
- maint_mgr->RegisterOp(mrs_flush_op.get());
- maintenance_ops_.push_back(mrs_flush_op.release());
-
- gscoped_ptr<MaintenanceOp> dms_flush_op(new FlushDeltaMemStoresOp(this));
- maint_mgr->RegisterOp(dms_flush_op.get());
- maintenance_ops_.push_back(dms_flush_op.release());
-
- gscoped_ptr<MaintenanceOp> log_gc(new LogGCOp(this));
- maint_mgr->RegisterOp(log_gc.get());
- maintenance_ops_.push_back(log_gc.release());
-
- tablet_->RegisterMaintenanceOps(maint_mgr);
-}
-
-void TabletPeer::UnregisterMaintenanceOps() {
- DCHECK(state_change_lock_.is_locked());
- for (MaintenanceOp* op : maintenance_ops_) {
- op->Unregister();
- }
- STLDeleteElements(&maintenance_ops_);
-}
-
-Status FlushInflightsToLogCallback::WaitForInflightsAndFlushLog() {
- // This callback is triggered prior to any TabletMetadata flush.
- // The guarantee that we are trying to enforce is this:
- //
- // If an operation has been flushed to stable storage (eg a DRS or DeltaFile)
- // then its COMMIT message must be present in the log.
- //
- // The purpose for this is so that, during bootstrap, we can accurately identify
- // whether each operation has been flushed. If we don't see a COMMIT message for
- // an operation, then we assume it was not completely applied and needs to be
- // re-applied. Thus, if we had something on disk but with no COMMIT message,
- // we'd attempt to double-apply the write, resulting in an error (eg trying to
- // delete an already-deleted row).
- //
- // So, to enforce this property, we do two steps:
- //
- // 1) Wait for any operations which are already mid-Apply() to Commit() in MVCC.
- //
- // Because the operations always enqueue their COMMIT message to the log
- // before calling Commit(), this ensures that any in-flight operations have
- // their commit messages "en route".
- //
- // NOTE: we only wait for those operations that have started their Apply() phase.
- // Any operations which haven't yet started applying haven't made any changes
- // to in-memory state: thus, they obviously couldn't have made any changes to
- // on-disk storage either (data can only get to the disk by going through an in-memory
- // store). Only those that have started Apply() could have potentially written some
- // data which is now on disk.
- //
- // Perhaps more importantly, if we waited on operations that hadn't started their
- // Apply() phase, we might be waiting forever -- for example, if a follower has been
- // partitioned from its leader, it may have operations sitting around in flight
- // for quite a long time before eventually aborting or committing. This would
- // end up blocking all flushes if we waited on it.
- //
- // 2) Flush the log
- //
- // This ensures that the above-mentioned commit messages are not just enqueued
- // to the log, but also on disk.
- VLOG(1) << "T " << tablet_->metadata()->tablet_id()
- << ": Waiting for in-flight transactions to commit.";
- LOG_SLOW_EXECUTION(WARNING, 200, "Committing in-flights took a long time.") {
- tablet_->mvcc_manager()->WaitForApplyingTransactionsToCommit();
- }
- VLOG(1) << "T " << tablet_->metadata()->tablet_id()
- << ": Waiting for the log queue to be flushed.";
- LOG_SLOW_EXECUTION(WARNING, 200, "Flushing the Log queue took a long time.") {
- RETURN_NOT_OK(log_->WaitUntilAllFlushed());
- }
- return Status::OK();
-}
-
-
-} // namespace tablet
-} // namespace kudu
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/tablet_peer.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet_peer.h b/src/kudu/tablet/tablet_peer.h
deleted file mode 100644
index d622626..0000000
--- a/src/kudu/tablet/tablet_peer.h
+++ /dev/null
@@ -1,377 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#ifndef KUDU_TABLET_TABLET_PEER_H_
-#define KUDU_TABLET_TABLET_PEER_H_
-
-#include <map>
-#include <memory>
-#include <mutex>
-#include <string>
-#include <vector>
-
-#include "kudu/consensus/consensus.h"
-#include "kudu/consensus/log.h"
-#include "kudu/consensus/time_manager.h"
-#include "kudu/gutil/callback.h"
-#include "kudu/gutil/ref_counted.h"
-#include "kudu/tablet/tablet.h"
-#include "kudu/tablet/transaction_order_verifier.h"
-#include "kudu/tablet/transactions/transaction_tracker.h"
-#include "kudu/util/metrics.h"
-#include "kudu/util/semaphore.h"
-
-namespace kudu {
-
-namespace log {
-class LogAnchorRegistry;
-}
-
-namespace rpc {
-class Messenger;
-class ResultTracker;
-}
-
-namespace tserver {
-class CatchUpServiceTest;
-}
-
-class MaintenanceManager;
-class MaintenanceOp;
-
-namespace tablet {
-class LeaderTransactionDriver;
-class ReplicaTransactionDriver;
-class TabletPeer;
-class TabletStatusPB;
-class TabletStatusListener;
-class TransactionDriver;
-
-// Interface by which various tablet-related processes can report back their status
-// to TabletPeer without having to have a circular class dependency, and so that
-// those other classes can be easily tested without constructing a TabletPeer.
-class TabletStatusListener {
- public:
- virtual ~TabletStatusListener() {}
-
- virtual void StatusMessage(const std::string& status) = 0;
-};
-
-// A peer in a tablet consensus configuration, which coordinates writes to tablets.
-// Each time Write() is called this class appends a new entry to a replicated
-// state machine through a consensus algorithm, which makes sure that other
-// peers see the same updates in the same order. In addition to this, this
-// class also splits the work and coordinates multi-threaded execution.
-class TabletPeer : public RefCountedThreadSafe<TabletPeer>,
- public consensus::ReplicaTransactionFactory,
- public TabletStatusListener {
- public:
- TabletPeer(const scoped_refptr<TabletMetadata>& meta,
- const consensus::RaftPeerPB& local_peer_pb, ThreadPool* apply_pool,
- Callback<void(const std::string& reason)> mark_dirty_clbk);
-
- // Initializes the TabletPeer, namely creating the Log and initializing
- // Consensus.
- Status Init(const std::shared_ptr<tablet::Tablet>& tablet,
- const scoped_refptr<server::Clock>& clock,
- const std::shared_ptr<rpc::Messenger>& messenger,
- const scoped_refptr<rpc::ResultTracker>& result_tracker,
- const scoped_refptr<log::Log>& log,
- const scoped_refptr<MetricEntity>& metric_entity);
-
- // Starts the TabletPeer, making it available for Write()s. If this
- // TabletPeer is part of a consensus configuration this will connect it to other peers
- // in the consensus configuration.
- Status Start(const consensus::ConsensusBootstrapInfo& info);
-
- // Shutdown this tablet peer.
- // If a shutdown is already in progress, blocks until that shutdown is complete.
- void Shutdown();
-
- // Check that the tablet is in a RUNNING state.
- Status CheckRunning() const;
-
- // Wait until the tablet is in a RUNNING state or if there's a timeout.
- // TODO have a way to wait for any state?
- Status WaitUntilConsensusRunning(const MonoDelta& timeout);
-
- // Submits a write to a tablet and executes it asynchronously.
- // The caller is expected to build and pass a TrasactionContext that points
- // to the RPC WriteRequest, WriteResponse, RpcContext and to the tablet's
- // MvccManager.
- Status SubmitWrite(std::unique_ptr<WriteTransactionState> tx_state);
-
- // Called by the tablet service to start an alter schema transaction.
- //
- // The transaction contains all the information required to execute the
- // AlterSchema operation and send the response back.
- //
- // If the returned Status is OK, the response to the client will be sent
- // asynchronously. Otherwise the tablet service will have to send the response directly.
- //
- // The AlterSchema operation is taking the tablet component lock in exclusive mode
- // meaning that no other operation on the tablet can be executed while the
- // AlterSchema is in progress.
- Status SubmitAlterSchema(std::unique_ptr<AlterSchemaTransactionState> tx_state);
-
- void GetTabletStatusPB(TabletStatusPB* status_pb_out) const;
-
- // Used by consensus to create and start a new ReplicaTransaction.
- virtual Status StartReplicaTransaction(
- const scoped_refptr<consensus::ConsensusRound>& round) OVERRIDE;
-
- consensus::Consensus* consensus() {
- std::lock_guard<simple_spinlock> lock(lock_);
- return consensus_.get();
- }
-
- scoped_refptr<consensus::Consensus> shared_consensus() const {
- std::lock_guard<simple_spinlock> lock(lock_);
- return consensus_;
- }
-
- Tablet* tablet() const {
- std::lock_guard<simple_spinlock> lock(lock_);
- return tablet_.get();
- }
-
- scoped_refptr<consensus::TimeManager> time_manager() const {
- return consensus_->time_manager();
- }
-
- std::shared_ptr<Tablet> shared_tablet() const {
- std::lock_guard<simple_spinlock> lock(lock_);
- return tablet_;
- }
-
- const TabletStatePB state() const {
- std::lock_guard<simple_spinlock> lock(lock_);
- return state_;
- }
-
- // Returns the current Raft configuration.
- const consensus::RaftConfigPB RaftConfig() const;
-
- // If any peers in the consensus configuration lack permanent uuids, get them via an
- // RPC call and update.
- // TODO: move this to raft_consensus.h.
- Status UpdatePermanentUuids();
-
- // Sets the tablet to a BOOTSTRAPPING state, indicating it is starting up.
- void SetBootstrapping() {
- std::lock_guard<simple_spinlock> lock(lock_);
- CHECK_EQ(NOT_STARTED, state_);
- state_ = BOOTSTRAPPING;
- }
-
- // Implementation of TabletStatusListener::StatusMessage().
- void StatusMessage(const std::string& status) override;
-
- // Retrieve the last human-readable status of this tablet peer.
- std::string last_status() const;
-
- // Sets the tablet state to FAILED additionally setting the error to the provided
- // one.
- void SetFailed(const Status& error);
-
- // Returns the error that occurred, when state is FAILED.
- Status error() const {
- std::lock_guard<simple_spinlock> lock(lock_);
- return error_;
- }
-
- // Returns a human-readable string indicating the state of the tablet.
- // Typically this looks like "NOT_STARTED", "TABLET_DATA_COPYING",
- // etc. For use in places like the Web UI.
- std::string HumanReadableState() const;
-
- // Adds list of transactions in-flight at the time of the call to 'out'.
- void GetInFlightTransactions(Transaction::TraceType trace_type,
- std::vector<consensus::TransactionStatusPB>* out) const;
-
- // Returns the log indexes to be retained for durability and to catch up peers.
- // Used for selection of log segments to delete during Log GC.
- log::RetentionIndexes GetRetentionIndexes() const;
-
- // See Log::GetReplaySizeMap(...).
- //
- // Returns a non-ok status if the tablet isn't running.
- Status GetReplaySizeMap(std::map<int64_t, int64_t>* replay_size_map) const;
-
- // Returns the amount of bytes that would be GC'd if RunLogGC() was called.
- //
- // Returns a non-ok status if the tablet isn't running.
- Status GetGCableDataSize(int64_t* retention_size) const;
-
- // Return a pointer to the Log.
- // TabletPeer keeps a reference to Log after Init().
- log::Log* log() const {
- return log_.get();
- }
-
- server::Clock* clock() {
- return clock_.get();
- }
-
- const scoped_refptr<log::LogAnchorRegistry>& log_anchor_registry() const {
- return log_anchor_registry_;
- }
-
- // Returns the tablet_id of the tablet managed by this TabletPeer.
- // Returns the correct tablet_id even if the underlying tablet is not available
- // yet.
- const std::string& tablet_id() const { return tablet_id_; }
-
- // Convenience method to return the permanent_uuid of this peer.
- std::string permanent_uuid() const { return tablet_->metadata()->fs_manager()->uuid(); }
-
- Status NewLeaderTransactionDriver(gscoped_ptr<Transaction> transaction,
- scoped_refptr<TransactionDriver>* driver);
-
- Status NewReplicaTransactionDriver(gscoped_ptr<Transaction> transaction,
- scoped_refptr<TransactionDriver>* driver);
-
- // Tells the tablet's log to garbage collect.
- Status RunLogGC();
-
- // Register the maintenance ops associated with this peer's tablet, also invokes
- // Tablet::RegisterMaintenanceOps().
- void RegisterMaintenanceOps(MaintenanceManager* maintenance_manager);
-
- // Unregister the maintenance ops associated with this peer's tablet.
- // This method is not thread safe.
- void UnregisterMaintenanceOps();
-
- // Return pointer to the transaction tracker for this peer.
- const TransactionTracker* transaction_tracker() const { return &txn_tracker_; }
-
- const scoped_refptr<TabletMetadata>& tablet_metadata() const {
- return meta_;
- }
-
- // Marks the tablet as dirty so that it's included in the next heartbeat.
- void MarkTabletDirty(const std::string& reason) {
- mark_dirty_clbk_.Run(reason);
- }
-
- private:
- friend class RefCountedThreadSafe<TabletPeer>;
- friend class TabletPeerTest;
- FRIEND_TEST(TabletPeerTest, TestMRSAnchorPreventsLogGC);
- FRIEND_TEST(TabletPeerTest, TestDMSAnchorPreventsLogGC);
- FRIEND_TEST(TabletPeerTest, TestActiveTransactionPreventsLogGC);
-
- ~TabletPeer();
-
- // Wait until the TabletPeer is fully in SHUTDOWN state.
- void WaitUntilShutdown();
-
- // After bootstrap is complete and consensus is setup this initiates the transactions
- // that were not complete on bootstrap.
- // Not implemented yet. See .cc file.
- Status StartPendingTransactions(consensus::RaftPeerPB::Role my_role,
- const consensus::ConsensusBootstrapInfo& bootstrap_info);
-
- const scoped_refptr<TabletMetadata> meta_;
-
- const std::string tablet_id_;
-
- const consensus::RaftPeerPB local_peer_pb_;
-
- TabletStatePB state_;
- Status error_;
- TransactionTracker txn_tracker_;
- TransactionOrderVerifier txn_order_verifier_;
- scoped_refptr<log::Log> log_;
- std::shared_ptr<Tablet> tablet_;
- std::shared_ptr<rpc::Messenger> messenger_;
- scoped_refptr<consensus::Consensus> consensus_;
- simple_spinlock prepare_replicate_lock_;
-
- // Lock protecting state_, last_status_, as well as smart pointers to collaborating
- // classes such as tablet_ and consensus_.
- mutable simple_spinlock lock_;
-
- // The human-readable last status of the tablet, displayed on the web page, command line
- // tools, etc.
- std::string last_status_;
-
- // Lock taken during Init/Shutdown which ensures that only a single thread
- // attempts to perform major lifecycle operations (Init/Shutdown) at once.
- // This must be acquired before acquiring lock_ if they are acquired together.
- // We don't just use lock_ since the lifecycle operations may take a while
- // and we'd like other threads to be able to quickly poll the state_ variable
- // during them in order to reject RPCs, etc.
- mutable simple_spinlock state_change_lock_;
-
- // IMPORTANT: correct execution of PrepareTask assumes that 'prepare_pool_'
- // is single-threaded, moving to a multi-tablet setup where multiple TabletPeers
- // use the same 'prepare_pool_' needs to enforce that, for a single
- // TabletPeer, PrepareTasks are executed *serially*.
- // TODO move the prepare pool to TabletServer.
- gscoped_ptr<ThreadPool> prepare_pool_;
-
- // Pool that executes apply tasks for transactions. This is a multi-threaded
- // pool, constructor-injected by either the Master (for system tables) or
- // the Tablet server.
- ThreadPool* apply_pool_;
-
- scoped_refptr<server::Clock> clock_;
-
- scoped_refptr<log::LogAnchorRegistry> log_anchor_registry_;
-
- // Function to mark this TabletPeer's tablet as dirty in the TSTabletManager.
- //
- // Must be called whenever cluster membership or leadership changes, or when
- // the tablet's schema changes.
- Callback<void(const std::string& reason)> mark_dirty_clbk_;
-
- // List of maintenance operations for the tablet that need information that only the peer
- // can provide.
- std::vector<MaintenanceOp*> maintenance_ops_;
-
- // The result tracker for writes.
- scoped_refptr<rpc::ResultTracker> result_tracker_;
-
- DISALLOW_COPY_AND_ASSIGN(TabletPeer);
-};
-
-// A callback to wait for the in-flight transactions to complete and to flush
-// the Log when they do.
-// Tablet is passed as a raw pointer as this callback is set in TabletMetadata and
-// were we to keep the tablet as a shared_ptr a circular dependency would occur:
-// callback->tablet->metadata->callback. Since the tablet indirectly owns this
-// callback we know that is must still be alive when it fires.
-class FlushInflightsToLogCallback : public RefCountedThreadSafe<FlushInflightsToLogCallback> {
- public:
- FlushInflightsToLogCallback(Tablet* tablet,
- const scoped_refptr<log::Log>& log)
- : tablet_(tablet),
- log_(log) {}
-
- Status WaitForInflightsAndFlushLog();
-
- private:
- Tablet* tablet_;
- scoped_refptr<log::Log> log_;
-};
-
-
-} // namespace tablet
-} // namespace kudu
-
-#endif /* KUDU_TABLET_TABLET_PEER_H_ */
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/tablet_peer_mm_ops.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet_peer_mm_ops.cc b/src/kudu/tablet/tablet_peer_mm_ops.cc
deleted file mode 100644
index 508d69f..0000000
--- a/src/kudu/tablet/tablet_peer_mm_ops.cc
+++ /dev/null
@@ -1,244 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#include "kudu/tablet/tablet_peer_mm_ops.h"
-
-#include <algorithm>
-#include <gflags/gflags.h>
-#include <map>
-#include <mutex>
-#include <string>
-
-#include "kudu/gutil/strings/substitute.h"
-#include "kudu/tablet/tablet_metrics.h"
-#include "kudu/util/flag_tags.h"
-#include "kudu/util/maintenance_manager.h"
-#include "kudu/util/metrics.h"
-
-DEFINE_int32(flush_threshold_mb, 1024,
- "Size at which MemRowSet flushes are triggered. "
- "A MRS can still flush below this threshold if it if hasn't flushed in a while, "
- "or if the server-wide memory limit has been reached.");
-TAG_FLAG(flush_threshold_mb, experimental);
-
-DEFINE_int32(flush_threshold_secs, 2 * 60,
- "Number of seconds after which a non-empty MemRowSet will become flushable "
- "even if it is not large.");
-TAG_FLAG(flush_threshold_secs, experimental);
-
-
-METRIC_DEFINE_gauge_uint32(tablet, log_gc_running,
- "Log GCs Running",
- kudu::MetricUnit::kOperations,
- "Number of log GC operations currently running.");
-METRIC_DEFINE_histogram(tablet, log_gc_duration,
- "Log GC Duration",
- kudu::MetricUnit::kMilliseconds,
- "Time spent garbage collecting the logs.", 60000LU, 1);
-
-namespace kudu {
-namespace tablet {
-
-using std::map;
-using strings::Substitute;
-
-// Upper bound for how long it takes to reach "full perf improvement" in time-based flushing.
-const double kFlushUpperBoundMs = 60 * 60 * 1000;
-
-//
-// FlushOpPerfImprovementPolicy.
-//
-
-void FlushOpPerfImprovementPolicy::SetPerfImprovementForFlush(MaintenanceOpStats* stats,
- double elapsed_ms) {
- if (stats->ram_anchored() > FLAGS_flush_threshold_mb * 1024 * 1024) {
- // If we're over the user-specified flush threshold, then consider the perf
- // improvement to be 1 for every extra MB. This produces perf_improvement results
- // which are much higher than any compaction would produce, and means that, when
- // there is an MRS over threshold, a flush will almost always be selected instead of
- // a compaction. That's not necessarily a good thing, but in the absence of better
- // heuristics, it will do for now.
- double extra_mb =
- static_cast<double>(FLAGS_flush_threshold_mb - (stats->ram_anchored()) / (1024 * 1024));
- stats->set_perf_improvement(extra_mb);
- } else if (elapsed_ms > FLAGS_flush_threshold_secs * 1000) {
- // Even if we aren't over the threshold, consider flushing if we haven't flushed
- // in a long time. But, don't give it a large perf_improvement score. We should
- // only do this if we really don't have much else to do, and if we've already waited a bit.
- // The following will give an improvement that's between 0.0 and 1.0, gradually growing
- // as 'elapsed_ms' approaches 'kFlushUpperBoundMs'.
- double perf = elapsed_ms / kFlushUpperBoundMs;
- if (perf > 1.0) {
- perf = 1.0;
- }
- stats->set_perf_improvement(perf);
- }
-}
-
-//
-// FlushMRSOp.
-//
-
-void FlushMRSOp::UpdateStats(MaintenanceOpStats* stats) {
- std::lock_guard<simple_spinlock> l(lock_);
-
- map<int64_t, int64_t> replay_size_map;
- if (tablet_peer_->tablet()->MemRowSetEmpty() ||
- !tablet_peer_->GetReplaySizeMap(&replay_size_map).ok()) {
- return;
- }
-
- {
- std::unique_lock<Semaphore> lock(tablet_peer_->tablet()->rowsets_flush_sem_, std::defer_lock);
- stats->set_runnable(lock.try_lock());
- }
-
- stats->set_ram_anchored(tablet_peer_->tablet()->MemRowSetSize());
- stats->set_logs_retained_bytes(
- tablet_peer_->tablet()->MemRowSetLogReplaySize(replay_size_map));
-
- // TODO(todd): use workload statistics here to find out how "hot" the tablet has
- // been in the last 5 minutes.
- FlushOpPerfImprovementPolicy::SetPerfImprovementForFlush(
- stats,
- time_since_flush_.elapsed().wall_millis());
-}
-
-bool FlushMRSOp::Prepare() {
- // Try to acquire the rowsets_flush_sem_. If we can't, the Prepare step
- // fails. This also implies that only one instance of FlushMRSOp can be
- // running at once.
- return tablet_peer_->tablet()->rowsets_flush_sem_.try_lock();
-}
-
-void FlushMRSOp::Perform() {
- CHECK(!tablet_peer_->tablet()->rowsets_flush_sem_.try_lock());
-
- KUDU_CHECK_OK_PREPEND(tablet_peer_->tablet()->FlushUnlocked(),
- Substitute("FlushMRS failed on $0", tablet_peer_->tablet_id()));
-
- {
- std::lock_guard<simple_spinlock> l(lock_);
- time_since_flush_.start();
- }
- tablet_peer_->tablet()->rowsets_flush_sem_.unlock();
-}
-
-scoped_refptr<Histogram> FlushMRSOp::DurationHistogram() const {
- return tablet_peer_->tablet()->metrics()->flush_mrs_duration;
-}
-
-scoped_refptr<AtomicGauge<uint32_t> > FlushMRSOp::RunningGauge() const {
- return tablet_peer_->tablet()->metrics()->flush_mrs_running;
-}
-
-//
-// FlushDeltaMemStoresOp.
-//
-
-void FlushDeltaMemStoresOp::UpdateStats(MaintenanceOpStats* stats) {
- std::lock_guard<simple_spinlock> l(lock_);
- int64_t dms_size;
- int64_t retention_size;
- map<int64_t, int64_t> max_idx_to_replay_size;
- if (tablet_peer_->tablet()->DeltaMemRowSetEmpty() ||
- !tablet_peer_->GetReplaySizeMap(&max_idx_to_replay_size).ok()) {
- return;
- }
- tablet_peer_->tablet()->GetInfoForBestDMSToFlush(max_idx_to_replay_size,
- &dms_size, &retention_size);
-
- stats->set_ram_anchored(dms_size);
- stats->set_runnable(true);
- stats->set_logs_retained_bytes(retention_size);
-
- FlushOpPerfImprovementPolicy::SetPerfImprovementForFlush(
- stats,
- time_since_flush_.elapsed().wall_millis());
-}
-
-void FlushDeltaMemStoresOp::Perform() {
- map<int64_t, int64_t> max_idx_to_replay_size;
- if (!tablet_peer_->GetReplaySizeMap(&max_idx_to_replay_size).ok()) {
- LOG(WARNING) << "Won't flush deltas since tablet shutting down: " << tablet_peer_->tablet_id();
- return;
- }
- KUDU_CHECK_OK_PREPEND(tablet_peer_->tablet()->FlushDMSWithHighestRetention(
- max_idx_to_replay_size),
- Substitute("Failed to flush DMS on $0",
- tablet_peer_->tablet()->tablet_id()));
- {
- std::lock_guard<simple_spinlock> l(lock_);
- time_since_flush_.start();
- }
-}
-
-scoped_refptr<Histogram> FlushDeltaMemStoresOp::DurationHistogram() const {
- return tablet_peer_->tablet()->metrics()->flush_dms_duration;
-}
-
-scoped_refptr<AtomicGauge<uint32_t> > FlushDeltaMemStoresOp::RunningGauge() const {
- return tablet_peer_->tablet()->metrics()->flush_dms_running;
-}
-
-//
-// LogGCOp.
-//
-
-LogGCOp::LogGCOp(TabletPeer* tablet_peer)
- : MaintenanceOp(StringPrintf("LogGCOp(%s)", tablet_peer->tablet()->tablet_id().c_str()),
- MaintenanceOp::LOW_IO_USAGE),
- tablet_peer_(tablet_peer),
- log_gc_duration_(METRIC_log_gc_duration.Instantiate(
- tablet_peer->tablet()->GetMetricEntity())),
- log_gc_running_(METRIC_log_gc_running.Instantiate(
- tablet_peer->tablet()->GetMetricEntity(), 0)),
- sem_(1) {}
-
-void LogGCOp::UpdateStats(MaintenanceOpStats* stats) {
- int64_t retention_size;
-
- if (!tablet_peer_->GetGCableDataSize(&retention_size).ok()) {
- return;
- }
-
- stats->set_logs_retained_bytes(retention_size);
- stats->set_runnable(sem_.GetValue() == 1);
-}
-
-bool LogGCOp::Prepare() {
- return sem_.try_lock();
-}
-
-void LogGCOp::Perform() {
- CHECK(!sem_.try_lock());
-
- tablet_peer_->RunLogGC();
-
- sem_.unlock();
-}
-
-scoped_refptr<Histogram> LogGCOp::DurationHistogram() const {
- return log_gc_duration_;
-}
-
-scoped_refptr<AtomicGauge<uint32_t> > LogGCOp::RunningGauge() const {
- return log_gc_running_;
-}
-
-} // namespace tablet
-} // namespace kudu
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/tablet_peer_mm_ops.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet_peer_mm_ops.h b/src/kudu/tablet/tablet_peer_mm_ops.h
deleted file mode 100644
index a985802..0000000
--- a/src/kudu/tablet/tablet_peer_mm_ops.h
+++ /dev/null
@@ -1,133 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#ifndef KUDU_TABLET_TABLET_PEER_MM_OPS_H_
-#define KUDU_TABLET_TABLET_PEER_MM_OPS_H_
-
-#include "kudu/tablet/tablet_peer.h"
-#include "kudu/util/maintenance_manager.h"
-#include "kudu/util/stopwatch.h"
-
-namespace kudu {
-
-class Histogram;
-template<class T>
-class AtomicGauge;
-
-namespace tablet {
-
-class FlushOpPerfImprovementPolicy {
- public:
- ~FlushOpPerfImprovementPolicy() {}
-
- // Sets the performance improvement based on the anchored ram if it's over the threshold,
- // else it will set it based on how long it has been since the last flush.
- static void SetPerfImprovementForFlush(MaintenanceOpStats* stats, double elapsed_ms);
-
- private:
- FlushOpPerfImprovementPolicy() {}
-};
-
-// Maintenance op for MRS flush. Only one can happen at a time.
-class FlushMRSOp : public MaintenanceOp {
- public:
- explicit FlushMRSOp(TabletPeer* tablet_peer)
- : MaintenanceOp(StringPrintf("FlushMRSOp(%s)", tablet_peer->tablet()->tablet_id().c_str()),
- MaintenanceOp::HIGH_IO_USAGE),
- tablet_peer_(tablet_peer) {
- time_since_flush_.start();
- }
-
- virtual void UpdateStats(MaintenanceOpStats* stats) OVERRIDE;
-
- virtual bool Prepare() OVERRIDE;
-
- virtual void Perform() OVERRIDE;
-
- virtual scoped_refptr<Histogram> DurationHistogram() const OVERRIDE;
-
- virtual scoped_refptr<AtomicGauge<uint32_t> > RunningGauge() const OVERRIDE;
-
- private:
- // Lock protecting time_since_flush_.
- mutable simple_spinlock lock_;
- Stopwatch time_since_flush_;
-
- TabletPeer *const tablet_peer_;
-};
-
-// Maintenance op for DMS flush.
-// Reports stats for all the DMS this tablet contains but only flushes one in Perform().
-class FlushDeltaMemStoresOp : public MaintenanceOp {
- public:
- explicit FlushDeltaMemStoresOp(TabletPeer* tablet_peer)
- : MaintenanceOp(StringPrintf("FlushDeltaMemStoresOp(%s)",
- tablet_peer->tablet()->tablet_id().c_str()),
- MaintenanceOp::HIGH_IO_USAGE),
- tablet_peer_(tablet_peer) {
- time_since_flush_.start();
- }
-
- virtual void UpdateStats(MaintenanceOpStats* stats) OVERRIDE;
-
- virtual bool Prepare() OVERRIDE {
- return true;
- }
-
- virtual void Perform() OVERRIDE;
-
- virtual scoped_refptr<Histogram> DurationHistogram() const OVERRIDE;
-
- virtual scoped_refptr<AtomicGauge<uint32_t> > RunningGauge() const OVERRIDE;
-
- private:
- // Lock protecting time_since_flush_
- mutable simple_spinlock lock_;
- Stopwatch time_since_flush_;
-
- TabletPeer *const tablet_peer_;
-};
-
-// Maintenance task that runs log GC. Reports log retention that represents the amount of data
-// that can be GC'd.
-//
-// Only one LogGC op can run at a time.
-class LogGCOp : public MaintenanceOp {
- public:
- explicit LogGCOp(TabletPeer* tablet_peer);
-
- virtual void UpdateStats(MaintenanceOpStats* stats) OVERRIDE;
-
- virtual bool Prepare() OVERRIDE;
-
- virtual void Perform() OVERRIDE;
-
- virtual scoped_refptr<Histogram> DurationHistogram() const OVERRIDE;
-
- virtual scoped_refptr<AtomicGauge<uint32_t> > RunningGauge() const OVERRIDE;
-
- private:
- TabletPeer *const tablet_peer_;
- scoped_refptr<Histogram> log_gc_duration_;
- scoped_refptr<AtomicGauge<uint32_t> > log_gc_running_;
- mutable Semaphore sem_;
-};
-
-} // namespace tablet
-} // namespace kudu
-
-#endif /* KUDU_TABLET_TABLET_PEER_MM_OPS_H_ */
[5/5] kudu git commit: Rename TabletPeer to TabletReplica
Posted by mp...@apache.org.
Rename TabletPeer to TabletReplica
This class was confusingly named. This changes the class names as well
as all usages from TabletPeer to TabletReplica.
This was initially done with a Perl script, then the indentation was
corrected, the variable naming was updated, and the documentation was
modified by hand.
Change-Id: Icafecd47268c395a6c0ce0aed75d154f4ace7192
Reviewed-on: http://gerrit.cloudera.org:8080/6794
Tested-by: Kudu Jenkins
Reviewed-by: Will Berkeley <wd...@gmail.com>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/7f72105b
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/7f72105b
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/7f72105b
Branch: refs/heads/master
Commit: 7f72105b79b36480d132e0ed10f4cc7fbabd6dca
Parents: 14e9d3d
Author: Mike Percy <mp...@apache.org>
Authored: Wed May 3 13:39:03 2017 -0700
Committer: Mike Percy <mp...@apache.org>
Committed: Thu May 4 22:14:08 2017 +0000
----------------------------------------------------------------------
docs/design-docs/rpc-retry-and-failover.md | 4 +-
src/kudu/client/client-test.cc | 68 +-
src/kudu/consensus/consensus-test-util.h | 2 +-
src/kudu/consensus/consensus.h | 4 +-
src/kudu/consensus/log.cc | 4 +-
src/kudu/consensus/raft_consensus.cc | 2 +-
src/kudu/consensus/raft_consensus.h | 2 +-
src/kudu/integration-tests/alter_table-test.cc | 98 +--
src/kudu/integration-tests/consistency-itest.cc | 20 +-
.../integration-tests/delete_tablet-itest.cc | 34 +-
.../full_stack-insert-scan-test.cc | 10 +-
src/kudu/integration-tests/fuzz-itest.cc | 26 +-
.../tablet_history_gc-itest.cc | 20 +-
.../ts_tablet_manager-itest.cc | 26 +-
src/kudu/master/catalog_manager.cc | 26 +-
src/kudu/master/catalog_manager.h | 12 +-
src/kudu/master/sys_catalog.cc | 42 +-
src/kudu/master/sys_catalog.h | 18 +-
src/kudu/tablet/CMakeLists.txt | 6 +-
src/kudu/tablet/local_tablet_writer.h | 2 +-
src/kudu/tablet/metadata.proto | 4 +-
src/kudu/tablet/tablet-harness.h | 6 +-
src/kudu/tablet/tablet.h | 2 +-
src/kudu/tablet/tablet_bootstrap.cc | 4 +-
src/kudu/tablet/tablet_peer-test.cc | 564 ----------------
src/kudu/tablet/tablet_peer.cc | 672 -------------------
src/kudu/tablet/tablet_peer.h | 377 -----------
src/kudu/tablet/tablet_peer_mm_ops.cc | 244 -------
src/kudu/tablet/tablet_peer_mm_ops.h | 133 ----
src/kudu/tablet/tablet_replica-test.cc | 565 ++++++++++++++++
src/kudu/tablet/tablet_replica.cc | 669 ++++++++++++++++++
src/kudu/tablet/tablet_replica.h | 377 +++++++++++
src/kudu/tablet/tablet_replica_mm_ops.cc | 246 +++++++
src/kudu/tablet/tablet_replica_mm_ops.h | 133 ++++
.../transactions/alter_schema_transaction.cc | 10 +-
.../transactions/alter_schema_transaction.h | 4 +-
src/kudu/tablet/transactions/transaction.cc | 4 +-
src/kudu/tablet/transactions/transaction.h | 12 +-
.../tablet/transactions/transaction_driver.cc | 6 +-
.../tablet/transactions/transaction_tracker.cc | 6 +-
.../tablet/transactions/transaction_tracker.h | 2 +-
.../tablet/transactions/write_transaction.cc | 16 +-
.../tablet/transactions/write_transaction.h | 2 +-
src/kudu/tools/kudu-tool-test.cc | 44 +-
src/kudu/tserver/scanners-test.cc | 16 +-
src/kudu/tserver/scanners.cc | 10 +-
src/kudu/tserver/scanners.h | 14 +-
src/kudu/tserver/tablet_copy-test-base.h | 12 +-
src/kudu/tserver/tablet_copy_client-test.cc | 6 +-
src/kudu/tserver/tablet_copy_client.cc | 2 +-
src/kudu/tserver/tablet_copy_client.h | 2 +-
src/kudu/tserver/tablet_copy_service-test.cc | 2 +-
src/kudu/tserver/tablet_copy_service.cc | 16 +-
src/kudu/tserver/tablet_copy_service.h | 6 +-
.../tserver/tablet_copy_source_session-test.cc | 50 +-
src/kudu/tserver/tablet_copy_source_session.cc | 32 +-
src/kudu/tserver/tablet_copy_source_session.h | 12 +-
src/kudu/tserver/tablet_peer_lookup.h | 63 --
src/kudu/tserver/tablet_replica_lookup.h | 63 ++
src/kudu/tserver/tablet_server-test-base.h | 28 +-
src/kudu/tserver/tablet_server-test.cc | 106 +--
src/kudu/tserver/tablet_service.cc | 174 ++---
src/kudu/tserver/tablet_service.h | 12 +-
src/kudu/tserver/ts_tablet_manager-test.cc | 32 +-
src/kudu/tserver/ts_tablet_manager.cc | 191 +++---
src/kudu/tserver/ts_tablet_manager.h | 54 +-
src/kudu/tserver/tserver-path-handlers.cc | 124 ++--
67 files changed, 2779 insertions(+), 2776 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/docs/design-docs/rpc-retry-and-failover.md
----------------------------------------------------------------------
diff --git a/docs/design-docs/rpc-retry-and-failover.md b/docs/design-docs/rpc-retry-and-failover.md
index 0375f72..9bdb91a 100644
--- a/docs/design-docs/rpc-retry-and-failover.md
+++ b/docs/design-docs/rpc-retry-and-failover.md
@@ -47,7 +47,7 @@ it's not totally clear what happens when an RPC mutates multiple "server objects
what these server objects really are.
2. Handled ad-hoc by the client and the tablet server/master, outside of the RPC layer -
-With this option, we choose to handle errors at the TabletServer/TabletPeer, ad-hoc, and for
+With this option, we choose to handle errors at the TabletServer/TabletReplica, ad-hoc, and for
each different RPC. For specific RPCs like Write() this option seems to map to existing
components quite well. For instance the completion record can be the raft log and replica
replay would mean that it would be relatively easy to implement a retry rendezvous
@@ -58,7 +58,7 @@ error handling for operations that are not tablet server transactions.
such as retrying and retry rendez-vous logic, but other parts of the logic would be implemented
ad-hoc in other layers. For instance, for Write()s, the RPC layer would know how to sequence and
retry the RPCs but would delegate durability and cross-server replicated operation rendezvous
-to the tablet peer/transaction manager.
+to the tablet replica/transaction manager.
# Design choices
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/client/client-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/client-test.cc b/src/kudu/client/client-test.cc
index a78fadc..afc15d0 100644
--- a/src/kudu/client/client-test.cc
+++ b/src/kudu/client/client-test.cc
@@ -56,7 +56,7 @@
#include "kudu/rpc/messenger.h"
#include "kudu/security/tls_context.h"
#include "kudu/server/hybrid_clock.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tablet/transactions/write_transaction.h"
#include "kudu/tserver/mini_tablet_server.h"
#include "kudu/tserver/scanners.h"
@@ -117,7 +117,7 @@ using master::GetTableLocationsRequestPB;
using master::GetTableLocationsResponsePB;
using master::TabletLocationsPB;
using sp::shared_ptr;
-using tablet::TabletPeer;
+using tablet::TabletReplica;
using tserver::MiniTabletServer;
class ClientTest : public KuduTest {
@@ -240,10 +240,10 @@ class ClientTest : public KuduTest {
void FlushTablet(const string& tablet_id) {
for (int i = 0; i < cluster_->num_tablet_servers(); i++) {
- scoped_refptr<TabletPeer> tablet_peer;
+ scoped_refptr<TabletReplica> tablet_replica;
ASSERT_TRUE(cluster_->mini_tablet_server(i)->server()->tablet_manager()->LookupTablet(
- tablet_id, &tablet_peer));
- ASSERT_OK(tablet_peer->tablet()->Flush());
+ tablet_id, &tablet_replica));
+ ASSERT_OK(tablet_replica->tablet()->Flush());
}
}
@@ -3376,18 +3376,18 @@ TEST_F(ClientTest, TestBasicAlterOperations) {
ASSERT_STR_CONTAINS(s.ToString(), "unsupported alter operation: string_val");
}
- // Need a tablet peer for the next set of tests.
+ // Need a TabletReplica for the next set of tests.
string tablet_id = GetFirstTabletId(client_table_.get());
- scoped_refptr<TabletPeer> tablet_peer;
+ scoped_refptr<TabletReplica> tablet_replica;
ASSERT_TRUE(cluster_->mini_tablet_server(0)->server()->tablet_manager()->LookupTablet(
- tablet_id, &tablet_peer));
+ tablet_id, &tablet_replica));
{
gscoped_ptr<KuduTableAlterer> table_alterer(client_->NewTableAlterer(kTableName));
table_alterer->DropColumn("int_val")
->AddColumn("new_col")->Type(KuduColumnSchema::INT32);
ASSERT_OK(table_alterer->Alter());
- ASSERT_EQ(1, tablet_peer->tablet()->metadata()->schema_version());
+ ASSERT_EQ(1, tablet_replica->tablet()->metadata()->schema_version());
}
// Specifying an encoding incompatible with the column's type is an error.
@@ -3398,7 +3398,7 @@ TEST_F(ClientTest, TestBasicAlterOperations) {
Status s = table_alterer->Alter();
ASSERT_TRUE(s.IsNotSupported());
ASSERT_STR_CONTAINS(s.ToString(), "encoding GROUP_VARINT not supported for type BINARY");
- ASSERT_EQ(1, tablet_peer->tablet()->metadata()->schema_version());
+ ASSERT_EQ(1, tablet_replica->tablet()->metadata()->schema_version());
}
// Test adding a new column of type string.
@@ -3407,7 +3407,7 @@ TEST_F(ClientTest, TestBasicAlterOperations) {
table_alterer->AddColumn("new_string_val")->Type(KuduColumnSchema::STRING)
->Encoding(KuduColumnStorageAttributes::PREFIX_ENCODING);
ASSERT_OK(table_alterer->Alter());
- ASSERT_EQ(2, tablet_peer->tablet()->metadata()->schema_version());
+ ASSERT_EQ(2, tablet_replica->tablet()->metadata()->schema_version());
}
// Test renaming a primary key column.
@@ -3416,7 +3416,7 @@ TEST_F(ClientTest, TestBasicAlterOperations) {
table_alterer->AlterColumn("key")->RenameTo("key2");
Status s = table_alterer->Alter();
ASSERT_FALSE(s.IsInvalidArgument());
- ASSERT_EQ(3, tablet_peer->tablet()->metadata()->schema_version());
+ ASSERT_EQ(3, tablet_replica->tablet()->metadata()->schema_version());
}
// Changing the type of a primary key column is an error.
@@ -3435,8 +3435,8 @@ TEST_F(ClientTest, TestBasicAlterOperations) {
table_alterer->AlterColumn("string_val")
->Default(KuduValue::CopyString("hello!"));
ASSERT_OK(table_alterer->Alter());
- ASSERT_EQ(4, tablet_peer->tablet()->metadata()->schema_version());
- Schema schema = tablet_peer->tablet()->metadata()->schema();
+ ASSERT_EQ(4, tablet_replica->tablet()->metadata()->schema_version());
+ Schema schema = tablet_replica->tablet()->metadata()->schema();
ColumnSchema col_schema = schema.column(schema.find_column("string_val"));
ASSERT_FALSE(col_schema.has_read_default());
ASSERT_TRUE(col_schema.has_write_default());
@@ -3449,8 +3449,8 @@ TEST_F(ClientTest, TestBasicAlterOperations) {
table_alterer->AlterColumn("non_null_with_default")
->Default(KuduValue::FromInt(54321));
ASSERT_OK(table_alterer->Alter());
- ASSERT_EQ(5, tablet_peer->tablet()->metadata()->schema_version());
- Schema schema = tablet_peer->tablet()->metadata()->schema();
+ ASSERT_EQ(5, tablet_replica->tablet()->metadata()->schema_version());
+ Schema schema = tablet_replica->tablet()->metadata()->schema();
ColumnSchema col_schema = schema.column(schema.find_column("non_null_with_default"));
ASSERT_TRUE(col_schema.has_read_default()); // Started with a default
ASSERT_TRUE(col_schema.has_write_default());
@@ -3463,8 +3463,8 @@ TEST_F(ClientTest, TestBasicAlterOperations) {
table_alterer->AlterColumn("string_val")
->RemoveDefault();
ASSERT_OK(table_alterer->Alter());
- ASSERT_EQ(6, tablet_peer->tablet()->metadata()->schema_version());
- Schema schema = tablet_peer->tablet()->metadata()->schema();
+ ASSERT_EQ(6, tablet_replica->tablet()->metadata()->schema_version());
+ Schema schema = tablet_replica->tablet()->metadata()->schema();
ColumnSchema col_schema = schema.column(schema.find_column("string_val"));
ASSERT_FALSE(col_schema.has_read_default());
ASSERT_FALSE(col_schema.has_write_default());
@@ -3476,8 +3476,8 @@ TEST_F(ClientTest, TestBasicAlterOperations) {
table_alterer->AlterColumn("non_null_with_default")
->RemoveDefault();
ASSERT_OK(table_alterer->Alter());
- ASSERT_EQ(7, tablet_peer->tablet()->metadata()->schema_version());
- Schema schema = tablet_peer->tablet()->metadata()->schema();
+ ASSERT_EQ(7, tablet_replica->tablet()->metadata()->schema_version());
+ Schema schema = tablet_replica->tablet()->metadata()->schema();
ColumnSchema col_schema = schema.column(schema.find_column("non_null_with_default"));
ASSERT_TRUE(col_schema.has_read_default());
ASSERT_FALSE(col_schema.has_write_default());
@@ -3494,7 +3494,7 @@ TEST_F(ClientTest, TestBasicAlterOperations) {
Status s = table_alterer->Alter();
ASSERT_TRUE(s.IsInvalidArgument());
ASSERT_STR_CONTAINS(s.ToString(), "wrong size for default value");
- ASSERT_EQ(7, tablet_peer->tablet()->metadata()->schema_version());
+ ASSERT_EQ(7, tablet_replica->tablet()->metadata()->schema_version());
}
// Test altering encoding, compression, and block size.
@@ -3505,8 +3505,8 @@ TEST_F(ClientTest, TestBasicAlterOperations) {
->Compression(KuduColumnStorageAttributes::LZ4)
->BlockSize(16 * 1024 * 1024);
ASSERT_OK(table_alterer->Alter());
- ASSERT_EQ(8, tablet_peer->tablet()->metadata()->schema_version());
- Schema schema = tablet_peer->tablet()->metadata()->schema();
+ ASSERT_EQ(8, tablet_replica->tablet()->metadata()->schema_version());
+ Schema schema = tablet_replica->tablet()->metadata()->schema();
ColumnSchema col_schema = schema.column(schema.find_column("string_val"));
ASSERT_EQ(KuduColumnStorageAttributes::PLAIN_ENCODING, col_schema.attributes().encoding);
ASSERT_EQ(KuduColumnStorageAttributes::LZ4, col_schema.attributes().compression);
@@ -3520,8 +3520,8 @@ TEST_F(ClientTest, TestBasicAlterOperations) {
ASSERT_OK(table_alterer
->RenameTo(kRenamedTableName)
->Alter());
- ASSERT_EQ(9, tablet_peer->tablet()->metadata()->schema_version());
- ASSERT_EQ(kRenamedTableName, tablet_peer->tablet()->metadata()->table_name());
+ ASSERT_EQ(9, tablet_replica->tablet()->metadata()->schema_version());
+ ASSERT_EQ(kRenamedTableName, tablet_replica->tablet()->metadata()->table_name());
CatalogManager *catalog_manager = cluster_->mini_master()->master()->catalog_manager();
CatalogManager::ScopedLeaderSharedLock l(catalog_manager);
@@ -3561,9 +3561,9 @@ TEST_F(ClientTest, TestDeleteTable) {
int wait_time = 1000;
bool tablet_found = true;
for (int i = 0; i < 80 && tablet_found; ++i) {
- scoped_refptr<TabletPeer> tablet_peer;
+ scoped_refptr<TabletReplica> tablet_replica;
tablet_found = cluster_->mini_tablet_server(0)->server()->tablet_manager()->LookupTablet(
- tablet_id, &tablet_peer);
+ tablet_id, &tablet_replica);
SleepFor(MonoDelta::FromMicroseconds(wait_time));
wait_time = std::min(wait_time * 5 / 4, 1000000);
}
@@ -4258,9 +4258,9 @@ TEST_F(ClientTest, TestInsertEmptyPK) {
ASSERT_OK(client_->OpenTable(kTableName, &table));
// Find the tablet.
- scoped_refptr<TabletPeer> tablet_peer;
+ scoped_refptr<TabletReplica> tablet_replica;
ASSERT_TRUE(cluster_->mini_tablet_server(0)->server()->tablet_manager()->LookupTablet(
- GetFirstTabletId(table.get()), &tablet_peer));
+ GetFirstTabletId(table.get()), &tablet_replica));
// Utility function to get the current value of the row.
const auto ReadRowAsString = [&]() {
@@ -4285,7 +4285,7 @@ TEST_F(ClientTest, TestInsertEmptyPK) {
ASSERT_EQ("(string k1=\"\", string v1=\"initial\")", ReadRowAsString());
// Make sure that Flush works properly, and the data is still readable.
- ASSERT_OK(tablet_peer->tablet()->Flush());
+ ASSERT_OK(tablet_replica->tablet()->Flush());
ASSERT_EQ("(string k1=\"\", string v1=\"initial\")", ReadRowAsString());
// Perform an update.
@@ -4297,9 +4297,9 @@ TEST_F(ClientTest, TestInsertEmptyPK) {
ASSERT_OK(session->Flush());
}
ASSERT_EQ("(string k1=\"\", string v1=\"updated\")", ReadRowAsString());
- ASSERT_OK(tablet_peer->tablet()->FlushAllDMSForTests());
+ ASSERT_OK(tablet_replica->tablet()->FlushAllDMSForTests());
ASSERT_EQ("(string k1=\"\", string v1=\"updated\")", ReadRowAsString());
- ASSERT_OK(tablet_peer->tablet()->Compact(tablet::Tablet::FORCE_COMPACT_ALL));
+ ASSERT_OK(tablet_replica->tablet()->Compact(tablet::Tablet::FORCE_COMPACT_ALL));
ASSERT_EQ("(string k1=\"\", string v1=\"updated\")", ReadRowAsString());
// Perform a delete.
@@ -4310,9 +4310,9 @@ TEST_F(ClientTest, TestInsertEmptyPK) {
ASSERT_OK(session->Flush());
}
ASSERT_EQ("<none>", ReadRowAsString());
- ASSERT_OK(tablet_peer->tablet()->FlushAllDMSForTests());
+ ASSERT_OK(tablet_replica->tablet()->FlushAllDMSForTests());
ASSERT_EQ("<none>", ReadRowAsString());
- ASSERT_OK(tablet_peer->tablet()->Compact(tablet::Tablet::FORCE_COMPACT_ALL));
+ ASSERT_OK(tablet_replica->tablet()->Compact(tablet::Tablet::FORCE_COMPACT_ALL));
ASSERT_EQ("<none>", ReadRowAsString());
}
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/consensus/consensus-test-util.h
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/consensus-test-util.h b/src/kudu/consensus/consensus-test-util.h
index 72cdf93..89707aa 100644
--- a/src/kudu/consensus/consensus-test-util.h
+++ b/src/kudu/consensus/consensus-test-util.h
@@ -634,7 +634,7 @@ class TestDriver {
Log* log_;
};
-// A transaction factory for tests, usually this is implemented by TabletPeer.
+// A transaction factory for tests, usually this is implemented by TabletReplica.
class TestTransactionFactory : public ReplicaTransactionFactory {
public:
explicit TestTransactionFactory(Log* log) : consensus_(nullptr),
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/consensus/consensus.h
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/consensus.h b/src/kudu/consensus/consensus.h
index 78edae3..8ea313c 100644
--- a/src/kudu/consensus/consensus.h
+++ b/src/kudu/consensus/consensus.h
@@ -48,7 +48,7 @@ class Clock;
}
namespace tablet {
-class TabletPeer;
+class TabletReplica;
}
namespace tserver {
@@ -294,7 +294,7 @@ class Consensus : public RefCountedThreadSafe<Consensus> {
protected:
friend class RefCountedThreadSafe<Consensus>;
- friend class tablet::TabletPeer;
+ friend class tablet::TabletReplica;
friend class master::SysCatalogTable;
// This class is refcounted.
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/consensus/log.cc
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/log.cc b/src/kudu/consensus/log.cc
index a145767..4a6121d 100644
--- a/src/kudu/consensus/log.cc
+++ b/src/kudu/consensus/log.cc
@@ -499,9 +499,9 @@ Status Log::DoAppend(LogEntryBatch* entry_batch) {
// We keep track of the last-written OpId here.
// This is needed to initialize Consensus on startup.
if (entry_batch->type_ == REPLICATE) {
- // TODO Probably remove the code below as it looks suspicious: Tablet peer uses this
+ // TODO Probably remove the code below as it looks suspicious: TabletReplica uses this
// as 'safe' anchor as it believes it in the log, when it actually isn't, i.e. this
- // is not the last durable operation. Either move this to tablet peer (since we're
+ // is not the last durable operation. Either move this to TabletReplica (since we're
// using in flights anyway no need to scan for ids here) or actually delay doing this
// until fsync() has been done. See KUDU-527.
std::lock_guard<rw_spinlock> write_lock(last_entry_op_id_lock_);
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/consensus/raft_consensus.cc
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/raft_consensus.cc b/src/kudu/consensus/raft_consensus.cc
index f75057f..91040bb 100644
--- a/src/kudu/consensus/raft_consensus.cc
+++ b/src/kudu/consensus/raft_consensus.cc
@@ -1079,7 +1079,7 @@ Status RaftConsensus::UpdateReplica(const ConsensusRequestPB* request,
// state machine so, were we to crash afterwards, having the prepares in-flight
// won't hurt.
// - Prepares depend on factors external to consensus (the transaction drivers and
- // the tablet peer) so if for some reason they cannot be enqueued we must know
+ // the TabletReplica) so if for some reason they cannot be enqueued we must know
// before we try write them to the WAL. Once enqueued, we assume that prepare will
// always succeed on a replica transaction (because the leader already prepared them
// successfully, and thus we know they are valid).
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/consensus/raft_consensus.h
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/raft_consensus.h b/src/kudu/consensus/raft_consensus.h
index 98f2743..7d6c633 100644
--- a/src/kudu/consensus/raft_consensus.h
+++ b/src/kudu/consensus/raft_consensus.h
@@ -387,7 +387,7 @@ class RaftConsensus : public Consensus,
Status HandleTermAdvanceUnlocked(ConsensusTerm new_term,
ReplicaState::FlushToDisk flush = ReplicaState::FLUSH_TO_DISK);
- // Asynchronously (on thread_pool_) notify the tablet peer that the consensus configuration
+ // Asynchronously (on thread_pool_) notify the TabletReplica that the consensus configuration
// has changed, thus reporting it back to the master.
void MarkDirty(const std::string& reason);
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/integration-tests/alter_table-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/alter_table-test.cc b/src/kudu/integration-tests/alter_table-test.cc
index 76ed354..03d2395 100644
--- a/src/kudu/integration-tests/alter_table-test.cc
+++ b/src/kudu/integration-tests/alter_table-test.cc
@@ -40,7 +40,7 @@
#include "kudu/master/master-test-util.h"
#include "kudu/master/mini_master.h"
#include "kudu/server/hybrid_clock.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tserver/mini_tablet_server.h"
#include "kudu/tserver/tablet_server.h"
#include "kudu/tserver/ts_tablet_manager.h"
@@ -82,7 +82,7 @@ using std::map;
using std::pair;
using std::unique_ptr;
using std::vector;
-using tablet::TabletPeer;
+using tablet::TabletReplica;
class AlterTableTest : public KuduTest {
public:
@@ -125,37 +125,37 @@ class AlterTableTest : public KuduTest {
.Create());
if (num_replicas() == 1) {
- tablet_peer_ = LookupTabletPeer();
- ASSERT_OK(tablet_peer_->consensus()->WaitUntilLeaderForTests(MonoDelta::FromSeconds(10)));
+ tablet_replica_ = LookupTabletReplica();
+ ASSERT_OK(tablet_replica_->consensus()->WaitUntilLeaderForTests(MonoDelta::FromSeconds(10)));
}
LOG(INFO) << "Tablet successfully located";
}
void TearDown() override {
- tablet_peer_.reset();
+ tablet_replica_.reset();
cluster_->Shutdown();
}
- scoped_refptr<TabletPeer> LookupTabletPeer() {
- vector<scoped_refptr<TabletPeer> > peers;
- cluster_->mini_tablet_server(0)->server()->tablet_manager()->GetTabletPeers(&peers);
- CHECK_EQ(1, peers.size());
- return peers[0];
+ scoped_refptr<TabletReplica> LookupTabletReplica() {
+ vector<scoped_refptr<TabletReplica> > replicas;
+ cluster_->mini_tablet_server(0)->server()->tablet_manager()->GetTabletReplicas(&replicas);
+ CHECK_EQ(1, replicas.size());
+ return replicas[0];
}
void ShutdownTS() {
- // Drop the tablet_peer_ reference since the tablet peer becomes invalid once
+ // Drop the tablet_replica_ reference since the tablet replica becomes invalid once
// we shut down the server. Additionally, if we hold onto the reference,
// we'll end up calling the destructor from the test code instead of the
// normal location, which can cause crashes, etc.
- tablet_peer_.reset();
+ tablet_replica_.reset();
if (cluster_->mini_tablet_server(0)->server() != nullptr) {
cluster_->mini_tablet_server(0)->Shutdown();
}
}
void RestartTabletServer(int idx = 0) {
- tablet_peer_.reset();
+ tablet_replica_.reset();
if (cluster_->mini_tablet_server(idx)->server()) {
cluster_->mini_tablet_server(idx)->Shutdown();
ASSERT_OK(cluster_->mini_tablet_server(idx)->Restart());
@@ -165,7 +165,7 @@ class AlterTableTest : public KuduTest {
ASSERT_OK(cluster_->mini_tablet_server(idx)->WaitStarted());
if (idx == 0) {
- tablet_peer_ = LookupTabletPeer();
+ tablet_replica_ = LookupTabletReplica();
}
}
@@ -255,7 +255,7 @@ class AlterTableTest : public KuduTest {
KuduSchema schema_;
- scoped_refptr<TabletPeer> tablet_peer_;
+ scoped_refptr<TabletReplica> tablet_replica_;
atomic<bool> stop_threads_;
@@ -279,14 +279,14 @@ const char *AlterTableTest::kTableName = "fake-table";
// on the TS handling the tablet of the altered table.
// TODO: create and verify multiple tablets when the client will support that.
TEST_F(AlterTableTest, TestTabletReports) {
- ASSERT_EQ(0, tablet_peer_->tablet()->metadata()->schema_version());
+ ASSERT_EQ(0, tablet_replica_->tablet()->metadata()->schema_version());
ASSERT_OK(AddNewI32Column(kTableName, "new-i32", 0));
- ASSERT_EQ(1, tablet_peer_->tablet()->metadata()->schema_version());
+ ASSERT_EQ(1, tablet_replica_->tablet()->metadata()->schema_version());
}
// Verify that adding an existing column will return an "already present" error
TEST_F(AlterTableTest, TestAddExistingColumn) {
- ASSERT_EQ(0, tablet_peer_->tablet()->metadata()->schema_version());
+ ASSERT_EQ(0, tablet_replica_->tablet()->metadata()->schema_version());
{
Status s = AddNewI32Column(kTableName, "c1", 0);
@@ -294,7 +294,7 @@ TEST_F(AlterTableTest, TestAddExistingColumn) {
ASSERT_STR_CONTAINS(s.ToString(), "The column already exists: c1");
}
- ASSERT_EQ(0, tablet_peer_->tablet()->metadata()->schema_version());
+ ASSERT_EQ(0, tablet_replica_->tablet()->metadata()->schema_version());
}
// Verify that adding a NOT NULL column without defaults will return an error.
@@ -303,7 +303,7 @@ TEST_F(AlterTableTest, TestAddExistingColumn) {
// Our APIs for the client are designed such that it's impossible to send such
// a request.
TEST_F(AlterTableTest, TestAddNotNullableColumnWithoutDefaults) {
- ASSERT_EQ(0, tablet_peer_->tablet()->metadata()->schema_version());
+ ASSERT_EQ(0, tablet_replica_->tablet()->metadata()->schema_version());
{
AlterTableRequestPB req;
@@ -324,14 +324,14 @@ TEST_F(AlterTableTest, TestAddNotNullableColumnWithoutDefaults) {
ASSERT_STR_CONTAINS(s.ToString(), "column `c2`: NOT NULL columns must have a default");
}
- ASSERT_EQ(0, tablet_peer_->tablet()->metadata()->schema_version());
+ ASSERT_EQ(0, tablet_replica_->tablet()->metadata()->schema_version());
}
// Adding a nullable column with no default value should be equivalent
// to a NULL default.
TEST_F(AlterTableTest, TestAddNullableColumnWithoutDefault) {
InsertRows(0, 1);
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
{
gscoped_ptr<KuduTableAlterer> table_alterer(client_->NewTableAlterer(kTableName));
@@ -351,7 +351,7 @@ TEST_F(AlterTableTest, TestAddNullableColumnWithoutDefault) {
// Rename a primary key column
TEST_F(AlterTableTest, TestRenamePrimaryKeyColumn) {
InsertRows(0, 1);
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
{
gscoped_ptr<KuduTableAlterer> table_alterer(client_->NewTableAlterer(kTableName));
@@ -396,7 +396,7 @@ TEST_F(AlterTableTest, TestAddChangeRemoveColumnDefaultValue) {
}
InsertRows(0, 1);
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
{
unique_ptr<KuduTableAlterer> table_alterer(client_->NewTableAlterer(kTableName));
@@ -406,7 +406,7 @@ TEST_F(AlterTableTest, TestAddChangeRemoveColumnDefaultValue) {
}
InsertRows(1, 1);
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
vector<string> rows;
ScanToStrings(&rows);
@@ -423,7 +423,7 @@ TEST_F(AlterTableTest, TestAddChangeRemoveColumnDefaultValue) {
}
InsertRows(2, 1);
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
ScanToStrings(&rows);
ASSERT_EQ(3, rows.size());
@@ -443,7 +443,7 @@ TEST_F(AlterTableTest, TestAddChangeRemoveColumnDefaultValue) {
}
InsertRows(3, 1);
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
ScanToStrings(&rows);
ASSERT_EQ(4, rows.size());
@@ -498,7 +498,7 @@ TEST_F(AlterTableTest, TestAlterEmptyRLEBlock) {
// Verify that, if a tablet server is down when an alter command is issued,
// it will eventually receive the command when it restarts.
TEST_F(AlterTableTest, TestAlterOnTSRestart) {
- ASSERT_EQ(0, tablet_peer_->tablet()->metadata()->schema_version());
+ ASSERT_EQ(0, tablet_replica_->tablet()->metadata()->schema_version());
ShutdownTS();
@@ -520,12 +520,12 @@ TEST_F(AlterTableTest, TestAlterOnTSRestart) {
// Restart the TS and wait for the new schema
RestartTabletServer();
ASSERT_OK(WaitAlterTableCompletion(kTableName, 50));
- ASSERT_EQ(1, tablet_peer_->tablet()->metadata()->schema_version());
+ ASSERT_EQ(1, tablet_replica_->tablet()->metadata()->schema_version());
}
// Verify that nothing is left behind on cluster shutdown with pending async tasks
TEST_F(AlterTableTest, TestShutdownWithPendingTasks) {
- ASSERT_EQ(0, tablet_peer_->tablet()->metadata()->schema_version());
+ ASSERT_EQ(0, tablet_replica_->tablet()->metadata()->schema_version());
ShutdownTS();
@@ -548,7 +548,7 @@ TEST_F(AlterTableTest, TestRestartTSDuringAlter) {
return;
}
- ASSERT_EQ(0, tablet_peer_->tablet()->metadata()->schema_version());
+ ASSERT_EQ(0, tablet_replica_->tablet()->metadata()->schema_version());
Status s = AddNewI32Column(kTableName, "new-i32", 10,
MonoDelta::FromMilliseconds(1));
@@ -562,7 +562,7 @@ TEST_F(AlterTableTest, TestRestartTSDuringAlter) {
// Wait for the new schema
ASSERT_OK(WaitAlterTableCompletion(kTableName, 50));
- ASSERT_EQ(1, tablet_peer_->tablet()->metadata()->schema_version());
+ ASSERT_EQ(1, tablet_replica_->tablet()->metadata()->schema_version());
}
TEST_F(AlterTableTest, TestGetSchemaAfterAlterTable) {
@@ -785,7 +785,7 @@ TEST_F(AlterTableTest, TestBootstrapAfterAlters) {
ASSERT_OK(AddNewI32Column(kTableName, "c2", 12345));
InsertRows(0, 1);
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
InsertRows(1, 1);
UpdateRow(0, { {"c1", 10001} });
@@ -837,9 +837,9 @@ TEST_F(AlterTableTest, TestCompactAfterUpdatingRemovedColumn) {
ASSERT_OK(AddNewI32Column(kTableName, "c2", 12345));
InsertRows(0, 1);
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
InsertRows(1, 1);
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
NO_FATALS(ScanToStrings(&rows));
@@ -860,7 +860,7 @@ TEST_F(AlterTableTest, TestCompactAfterUpdatingRemovedColumn) {
ASSERT_EQ("(int32 c0=0, int32 c2=12345)", rows[0]);
// Compact
- ASSERT_OK(tablet_peer_->tablet()->Compact(tablet::Tablet::FORCE_COMPACT_ALL));
+ ASSERT_OK(tablet_replica_->tablet()->Compact(tablet::Tablet::FORCE_COMPACT_ALL));
}
// Test which major-compacts a column for which there are updates in
@@ -874,7 +874,7 @@ TEST_F(AlterTableTest, TestMajorCompactDeltasAfterUpdatingRemovedColumn) {
ASSERT_OK(AddNewI32Column(kTableName, "c2", 12345));
InsertRows(0, 1);
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
NO_FATALS(ScanToStrings(&rows));
ASSERT_EQ(1, rows.size());
@@ -884,7 +884,7 @@ TEST_F(AlterTableTest, TestMajorCompactDeltasAfterUpdatingRemovedColumn) {
UpdateRow(0, { {"c1", 54321} });
// Make sure the delta is in a delta-file.
- ASSERT_OK(tablet_peer_->tablet()->FlushBiggestDMS());
+ ASSERT_OK(tablet_replica_->tablet()->FlushBiggestDMS());
// Drop c1.
LOG(INFO) << "Dropping c1";
@@ -896,13 +896,13 @@ TEST_F(AlterTableTest, TestMajorCompactDeltasAfterUpdatingRemovedColumn) {
ASSERT_EQ("(int32 c0=0, int32 c2=12345)", rows[0]);
// Major Compact Deltas
- ASSERT_OK(tablet_peer_->tablet()->CompactWorstDeltas(
+ ASSERT_OK(tablet_replica_->tablet()->CompactWorstDeltas(
tablet::RowSet::MAJOR_DELTA_COMPACTION));
// Check via debug dump that the data was properly compacted, including deltas.
// We expect to see neither deltas nor base data for the deleted column.
rows.clear();
- tablet_peer_->tablet()->DebugDump(&rows);
+ tablet_replica_->tablet()->DebugDump(&rows);
ASSERT_EQ("Dumping tablet:\n"
"---------------------------\n"
"MRS memrowset:\n"
@@ -925,7 +925,7 @@ TEST_F(AlterTableTest, TestMajorCompactDeltasIntoMissingBaseData) {
vector<string> rows;
InsertRows(0, 2);
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
// Add the new column after the Flush, so it has no base data.
ASSERT_OK(AddNewI32Column(kTableName, "c2", 12345));
@@ -934,7 +934,7 @@ TEST_F(AlterTableTest, TestMajorCompactDeltasIntoMissingBaseData) {
UpdateRow(0, { {"c2", 54321} });
// Make sure the delta is in a delta-file.
- ASSERT_OK(tablet_peer_->tablet()->FlushBiggestDMS());
+ ASSERT_OK(tablet_replica_->tablet()->FlushBiggestDMS());
NO_FATALS(ScanToStrings(&rows));
ASSERT_EQ(2, rows.size());
@@ -942,7 +942,7 @@ TEST_F(AlterTableTest, TestMajorCompactDeltasIntoMissingBaseData) {
ASSERT_EQ("(int32 c0=16777216, int32 c1=1, int32 c2=12345)", rows[1]);
// Major Compact Deltas
- ASSERT_OK(tablet_peer_->tablet()->CompactWorstDeltas(
+ ASSERT_OK(tablet_replica_->tablet()->CompactWorstDeltas(
tablet::RowSet::MAJOR_DELTA_COMPACTION));
// Check via debug dump that the data was properly compacted, including deltas.
@@ -950,7 +950,7 @@ TEST_F(AlterTableTest, TestMajorCompactDeltasIntoMissingBaseData) {
// row, the default value materialized for the second, and a proper UNDO to undo
// the update on the first row.
rows.clear();
- tablet_peer_->tablet()->DebugDump(&rows);
+ tablet_replica_->tablet()->DebugDump(&rows);
ASSERT_EQ("Dumping tablet:\n"
"---------------------------\n"
"MRS memrowset:\n"
@@ -974,7 +974,7 @@ TEST_F(AlterTableTest, TestMajorCompactDeltasAfterAddUpdateRemoveColumn) {
vector<string> rows;
InsertRows(0, 1);
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
// Add the new column after the Flush(), so that no CFile for this
// column is present in the base data.
@@ -984,7 +984,7 @@ TEST_F(AlterTableTest, TestMajorCompactDeltasAfterAddUpdateRemoveColumn) {
UpdateRow(0, { {"c2", 54321} });
// Make sure the delta is in a delta-file.
- ASSERT_OK(tablet_peer_->tablet()->FlushBiggestDMS());
+ ASSERT_OK(tablet_replica_->tablet()->FlushBiggestDMS());
NO_FATALS(ScanToStrings(&rows));
ASSERT_EQ(1, rows.size());
@@ -1000,13 +1000,13 @@ TEST_F(AlterTableTest, TestMajorCompactDeltasAfterAddUpdateRemoveColumn) {
ASSERT_EQ("(int32 c0=0, int32 c1=0)", rows[0]);
// Major Compact Deltas
- ASSERT_OK(tablet_peer_->tablet()->CompactWorstDeltas(
+ ASSERT_OK(tablet_replica_->tablet()->CompactWorstDeltas(
tablet::RowSet::MAJOR_DELTA_COMPACTION));
// Check via debug dump that the data was properly compacted, including deltas.
// We expect to see neither deltas nor base data for the deleted column.
rows.clear();
- tablet_peer_->tablet()->DebugDump(&rows);
+ tablet_replica_->tablet()->DebugDump(&rows);
ASSERT_EQ("Dumping tablet:\n"
"---------------------------\n"
"MRS memrowset:\n"
@@ -1029,7 +1029,7 @@ TEST_F(AlterTableTest, TestReadHistoryAfterAlter) {
DeleteRow(0);
InsertRows(0, 1);
uint64_t ts1 = client_->GetLatestObservedTimestamp();
- ASSERT_OK(tablet_peer_->tablet()->Flush());
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
ASSERT_OK(AddNewI32Column(kTableName, "c2", 12345));
shared_ptr<KuduTable> table;
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/integration-tests/consistency-itest.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/consistency-itest.cc b/src/kudu/integration-tests/consistency-itest.cc
index 23a1f58..901b0d5 100644
--- a/src/kudu/integration-tests/consistency-itest.cc
+++ b/src/kudu/integration-tests/consistency-itest.cc
@@ -40,7 +40,7 @@
#include "kudu/integration-tests/mini_cluster.h"
#include "kudu/server/hybrid_clock.h"
#include "kudu/tablet/tablet.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tserver/mini_tablet_server.h"
#include "kudu/tserver/tablet_server.h"
#include "kudu/tserver/ts_tablet_manager.h"
@@ -59,7 +59,7 @@ using kudu::master::CatalogManager;
using kudu::master::GetTableLocationsRequestPB;
using kudu::master::GetTableLocationsResponsePB;
using kudu::server::HybridClock;
-using kudu::tablet::TabletPeer;
+using kudu::tablet::TabletReplica;
using kudu::tserver::MiniTabletServer;
using kudu::tserver::TabletServer;
using std::string;
@@ -198,24 +198,24 @@ class ConsistencyITest : public MiniClusterITestBase {
}
Status FindPeerForTablet(const string& tablet_id,
- scoped_refptr<TabletPeer>* peer) {
+ scoped_refptr<TabletReplica>* replica) {
bool found = false;
for (size_t i = 0; i < num_tablet_servers_; ++i) {
MiniTabletServer* mts = cluster_->mini_tablet_server(i);
TabletServer* ts = mts->server();
- scoped_refptr<TabletPeer> p;
- if (!ts->tablet_manager()->LookupTablet(tablet_id, &p)) {
+ scoped_refptr<TabletReplica> r;
+ if (!ts->tablet_manager()->LookupTablet(tablet_id, &r)) {
// Not this one, continue.
continue;
}
- peer->swap(p);
+ replica->swap(r);
found = true;
break;
}
if (!found) {
return Status::NotFound(
- Substitute("$0: cannot find peer for tablet"), tablet_id);
+ Substitute("$0: cannot find replica for tablet"), tablet_id);
}
return Status::OK();
}
@@ -223,10 +223,10 @@ class ConsistencyITest : public MiniClusterITestBase {
Status UpdateClockForTabletHostingKey(int32_t key, const MonoDelta& offset) {
string tablet_id;
RETURN_NOT_OK(GetTabletIdForKey(key, &tablet_id));
- scoped_refptr<TabletPeer> p;
- RETURN_NOT_OK(FindPeerForTablet(tablet_id, &p));
+ scoped_refptr<TabletReplica> r;
+ RETURN_NOT_OK(FindPeerForTablet(tablet_id, &r));
- HybridClock* clock = CHECK_NOTNULL(dynamic_cast<HybridClock*>(p->clock()));
+ HybridClock* clock = CHECK_NOTNULL(dynamic_cast<HybridClock*>(r->clock()));
UpdateClock(clock, offset);
return Status::OK();
}
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/integration-tests/delete_tablet-itest.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/delete_tablet-itest.cc b/src/kudu/integration-tests/delete_tablet-itest.cc
index af95003..0305991 100644
--- a/src/kudu/integration-tests/delete_tablet-itest.cc
+++ b/src/kudu/integration-tests/delete_tablet-itest.cc
@@ -23,14 +23,14 @@
#include "kudu/integration-tests/mini_cluster-itest-base.h"
#include "kudu/integration-tests/test_workload.h"
#include "kudu/master/mini_master.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tserver/mini_tablet_server.h"
#include "kudu/tserver/tablet_server.h"
#include "kudu/tserver/ts_tablet_manager.h"
DECLARE_int64(fs_wal_dir_reserved_bytes);
-using kudu::tablet::TabletPeer;
+using kudu::tablet::TabletReplica;
using std::vector;
namespace kudu {
@@ -53,12 +53,12 @@ TEST_F(DeleteTabletITest, TestDeleteFailedReplica) {
auto* mts = cluster_->mini_tablet_server(0);
auto* ts = ts_map[mts->uuid()];
- scoped_refptr<TabletPeer> tablet_peer;
+ scoped_refptr<TabletReplica> tablet_replica;
ASSERT_EVENTUALLY([&] {
- vector<scoped_refptr<TabletPeer>> tablet_peers;
- mts->server()->tablet_manager()->GetTabletPeers(&tablet_peers);
- ASSERT_EQ(1, tablet_peers.size());
- tablet_peer = tablet_peers[0];
+ vector<scoped_refptr<TabletReplica>> tablet_replicas;
+ mts->server()->tablet_manager()->GetTabletReplicas(&tablet_replicas);
+ ASSERT_EQ(1, tablet_replicas.size());
+ tablet_replica = tablet_replicas[0];
});
workload.Start();
@@ -68,7 +68,7 @@ TEST_F(DeleteTabletITest, TestDeleteFailedReplica) {
workload.StopAndJoin();
// We need blocks on-disk for this regression test, so force an MRS flush.
- ASSERT_OK(tablet_peer->tablet()->Flush());
+ ASSERT_OK(tablet_replica->tablet()->Flush());
// Shut down the master so it doesn't crash the test process when we make the
// disk appear to be full.
@@ -85,20 +85,20 @@ TEST_F(DeleteTabletITest, TestDeleteFailedReplica) {
// Tablet bootstrap failure should result in tablet status == FAILED.
{
- vector<scoped_refptr<TabletPeer>> tablet_peers;
- mts->server()->tablet_manager()->GetTabletPeers(&tablet_peers);
- ASSERT_EQ(1, tablet_peers.size());
- tablet_peer = tablet_peers[0];
- ASSERT_EQ(tablet::FAILED, tablet_peer->state());
+ vector<scoped_refptr<TabletReplica>> tablet_replicas;
+ mts->server()->tablet_manager()->GetTabletReplicas(&tablet_replicas);
+ ASSERT_EQ(1, tablet_replicas.size());
+ tablet_replica = tablet_replicas[0];
+ ASSERT_EQ(tablet::FAILED, tablet_replica->state());
}
// We should still be able to delete the failed tablet.
- ASSERT_OK(itest::DeleteTablet(ts, tablet_peer->tablet_id(), tablet::TABLET_DATA_DELETED,
+ ASSERT_OK(itest::DeleteTablet(ts, tablet_replica->tablet_id(), tablet::TABLET_DATA_DELETED,
boost::none, MonoDelta::FromSeconds(30)));
ASSERT_EVENTUALLY([&] {
- vector<scoped_refptr<TabletPeer>> tablet_peers;
- mts->server()->tablet_manager()->GetTabletPeers(&tablet_peers);
- ASSERT_EQ(0, tablet_peers.size());
+ vector<scoped_refptr<TabletReplica>> tablet_replicas;
+ mts->server()->tablet_manager()->GetTabletReplicas(&tablet_replicas);
+ ASSERT_EQ(0, tablet_replicas.size());
});
}
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/integration-tests/full_stack-insert-scan-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/full_stack-insert-scan-test.cc b/src/kudu/integration-tests/full_stack-insert-scan-test.cc
index eab7aff..c2160af 100644
--- a/src/kudu/integration-tests/full_stack-insert-scan-test.cc
+++ b/src/kudu/integration-tests/full_stack-insert-scan-test.cc
@@ -41,7 +41,7 @@
#include "kudu/master/mini_master.h"
#include "kudu/tablet/tablet.h"
#include "kudu/tablet/tablet_metrics.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tserver/mini_tablet_server.h"
#include "kudu/tserver/tablet_server.h"
#include "kudu/tserver/ts_tablet_manager.h"
@@ -325,10 +325,10 @@ void FullStackInsertScanTest::FlushToDisk() {
tserver::TabletServer* ts = cluster_->mini_tablet_server(i)->server();
ts->maintenance_manager()->Shutdown();
tserver::TSTabletManager* tm = ts->tablet_manager();
- vector<scoped_refptr<TabletPeer> > peers;
- tm->GetTabletPeers(&peers);
- for (const scoped_refptr<TabletPeer>& peer : peers) {
- Tablet* tablet = peer->tablet();
+ vector<scoped_refptr<TabletReplica> > replicas;
+ tm->GetTabletReplicas(&replicas);
+ for (const scoped_refptr<TabletReplica>& replica : replicas) {
+ Tablet* tablet = replica->tablet();
if (!tablet->MemRowSetEmpty()) {
ASSERT_OK(tablet->Flush());
}
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/integration-tests/fuzz-itest.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/fuzz-itest.cc b/src/kudu/integration-tests/fuzz-itest.cc
index 47b4095..f68784a 100644
--- a/src/kudu/integration-tests/fuzz-itest.cc
+++ b/src/kudu/integration-tests/fuzz-itest.cc
@@ -37,7 +37,7 @@
#include "kudu/server/logical_clock.h"
#include "kudu/tablet/key_value_test_schema.h"
#include "kudu/tablet/tablet.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tserver/mini_tablet_server.h"
#include "kudu/tserver/tablet_server.h"
#include "kudu/tserver/ts_tablet_manager.h"
@@ -192,8 +192,8 @@ class FuzzTest : public KuduTest {
.num_replicas(1)
.Create());
- // Find the peer.
- tablet_peer_ = LookupTabletPeer();
+ // Find the replica.
+ tablet_replica_ = LookupTabletReplica();
// Setup session and table.
session_ = client_->NewSession();
@@ -203,19 +203,19 @@ class FuzzTest : public KuduTest {
}
void TearDown() override {
- if (tablet_peer_) tablet_peer_.reset();
+ if (tablet_replica_) tablet_replica_.reset();
if (cluster_) cluster_->Shutdown();
}
- scoped_refptr<TabletPeer> LookupTabletPeer() {
- vector<scoped_refptr<TabletPeer> > peers;
- cluster_->mini_tablet_server(0)->server()->tablet_manager()->GetTabletPeers(&peers);
- CHECK_EQ(1, peers.size());
- return peers[0];
+ scoped_refptr<TabletReplica> LookupTabletReplica() {
+ vector<scoped_refptr<TabletReplica> > replicas;
+ cluster_->mini_tablet_server(0)->server()->tablet_manager()->GetTabletReplicas(&replicas);
+ CHECK_EQ(1, replicas.size());
+ return replicas[0];
}
void RestartTabletServer() {
- tablet_peer_.reset();
+ tablet_replica_.reset();
auto ts = cluster_->mini_tablet_server(0);
if (ts->server()) {
ts->Shutdown();
@@ -225,11 +225,11 @@ class FuzzTest : public KuduTest {
}
ASSERT_OK(ts->server()->WaitInited());
- tablet_peer_ = LookupTabletPeer();
+ tablet_replica_ = LookupTabletReplica();
}
Tablet* tablet() const {
- return tablet_peer_->tablet();
+ return tablet_replica_->tablet();
}
// Adds an insert for the given key/value pair to 'ops', returning the new contents
@@ -434,7 +434,7 @@ class FuzzTest : public KuduTest {
vector<optional<ExpectedKeyValueRow>>,
std::greater<int>> saved_values_;
- scoped_refptr<TabletPeer> tablet_peer_;
+ scoped_refptr<TabletReplica> tablet_replica_;
};
// The set of ops to draw from.
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/integration-tests/tablet_history_gc-itest.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/tablet_history_gc-itest.cc b/src/kudu/integration-tests/tablet_history_gc-itest.cc
index 4a40a6c..e307cd4 100644
--- a/src/kudu/integration-tests/tablet_history_gc-itest.cc
+++ b/src/kudu/integration-tests/tablet_history_gc-itest.cc
@@ -31,7 +31,7 @@
#include "kudu/tablet/local_tablet_writer.h"
#include "kudu/tablet/tablet.h"
#include "kudu/tablet/tablet_metrics.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tserver/mini_tablet_server.h"
#include "kudu/tserver/tablet_server.h"
#include "kudu/tserver/ts_tablet_manager.h"
@@ -42,7 +42,7 @@ using kudu::client::KuduTable;
using kudu::client::sp::shared_ptr;
using kudu::server::HybridClock;
using kudu::tablet::Tablet;
-using kudu::tablet::TabletPeer;
+using kudu::tablet::TabletReplica;
using kudu::tserver::MiniTabletServer;
using kudu::tserver::TabletServer;
using kudu::tserver::TSTabletManager;
@@ -121,10 +121,10 @@ TEST_F(TabletHistoryGcITest, TestUndoDeltaBlockGc) {
// Find the tablet.
tserver::MiniTabletServer* mts = cluster_->mini_tablet_server(0);
- vector<scoped_refptr<TabletPeer>> tablet_peers;
- mts->server()->tablet_manager()->GetTabletPeers(&tablet_peers);
- ASSERT_EQ(1, tablet_peers.size());
- std::shared_ptr<Tablet> tablet = tablet_peers[0]->shared_tablet();
+ vector<scoped_refptr<TabletReplica>> tablet_replicas;
+ mts->server()->tablet_manager()->GetTabletReplicas(&tablet_replicas);
+ ASSERT_EQ(1, tablet_replicas.size());
+ std::shared_ptr<Tablet> tablet = tablet_replicas[0]->shared_tablet();
const int32_t kNumRows = AllowSlowTests() ? 100 : 10;
@@ -500,10 +500,10 @@ TEST_F(RandomizedTabletHistoryGcITest, TestRandomHistoryGCWorkload) {
MiniTabletServer* mts = cluster_->mini_tablet_server(0);
TabletServer* ts = mts->server();
clock_ = down_cast<HybridClock*>(ts->clock());
- std::vector<scoped_refptr<TabletPeer>> peers;
- ts->tablet_manager()->GetTabletPeers(&peers);
- ASSERT_EQ(1, peers.size());
- Tablet* tablet = peers[0]->tablet();
+ std::vector<scoped_refptr<TabletReplica>> replicas;
+ ts->tablet_manager()->GetTabletReplicas(&replicas);
+ ASSERT_EQ(1, replicas.size());
+ Tablet* tablet = replicas[0]->tablet();
// Set initial clock time to 1000 seconds past 0, which is enough so that the
// AHM will not be negative.
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/integration-tests/ts_tablet_manager-itest.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/ts_tablet_manager-itest.cc b/src/kudu/integration-tests/ts_tablet_manager-itest.cc
index f841313..b632050 100644
--- a/src/kudu/integration-tests/ts_tablet_manager-itest.cc
+++ b/src/kudu/integration-tests/ts_tablet_manager-itest.cc
@@ -33,7 +33,7 @@
#include "kudu/master/mini_master.h"
#include "kudu/rpc/messenger.h"
#include "kudu/server/server_base.proxy.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tserver/heartbeater.h"
#include "kudu/tserver/mini_tablet_server.h"
#include "kudu/tserver/tablet_server.h"
@@ -67,7 +67,7 @@ using rpc::Messenger;
using rpc::MessengerBuilder;
using std::shared_ptr;
using strings::Substitute;
-using tablet::TabletPeer;
+using tablet::TabletReplica;
using tserver::MiniTabletServer;
using tserver::TSTabletManager;
@@ -134,21 +134,21 @@ TEST_F(TsTabletManagerITest, TestReportNewLeaderOnLeaderChange) {
ASSERT_OK(CreateTabletServerMap(master_proxy, client_messenger_, &ts_map));
ValueDeleter deleter(&ts_map);
- // Collect the tablet peers so we get direct access to consensus.
- vector<scoped_refptr<TabletPeer> > tablet_peers;
+ // Collect the TabletReplicas so we get direct access to Consensus.
+ vector<scoped_refptr<TabletReplica> > tablet_replicas;
for (int replica = 0; replica < kNumReplicas; replica++) {
MiniTabletServer* ts = cluster_->mini_tablet_server(replica);
ts->FailHeartbeats(); // Stop heartbeating we don't race against the Master.
- vector<scoped_refptr<TabletPeer> > cur_ts_tablet_peers;
+ vector<scoped_refptr<TabletReplica> > cur_ts_tablet_replicas;
// The replicas may not have been created yet, so loop until we see them.
while (true) {
- ts->server()->tablet_manager()->GetTabletPeers(&cur_ts_tablet_peers);
- if (!cur_ts_tablet_peers.empty()) break;
+ ts->server()->tablet_manager()->GetTabletReplicas(&cur_ts_tablet_replicas);
+ if (!cur_ts_tablet_replicas.empty()) break;
SleepFor(MonoDelta::FromMilliseconds(10));
}
- ASSERT_EQ(1, cur_ts_tablet_peers.size()); // Each TS should only have 1 tablet.
- ASSERT_OK(cur_ts_tablet_peers[0]->WaitUntilConsensusRunning(MonoDelta::FromSeconds(10)));
- tablet_peers.push_back(cur_ts_tablet_peers[0]);
+ ASSERT_EQ(1, cur_ts_tablet_replicas.size()); // Each TS should only have 1 tablet.
+ ASSERT_OK(cur_ts_tablet_replicas[0]->WaitUntilConsensusRunning(MonoDelta::FromSeconds(10)));
+ tablet_replicas.push_back(cur_ts_tablet_replicas[0]);
}
// Loop and cause elections and term changes from different servers.
@@ -157,11 +157,11 @@ TEST_F(TsTabletManagerITest, TestReportNewLeaderOnLeaderChange) {
SCOPED_TRACE(Substitute("Iter: $0", i));
int new_leader_idx = rand() % 2;
LOG(INFO) << "Electing peer " << new_leader_idx << "...";
- consensus::Consensus* con = CHECK_NOTNULL(tablet_peers[new_leader_idx]->consensus());
+ consensus::Consensus* con = CHECK_NOTNULL(tablet_replicas[new_leader_idx]->consensus());
ASSERT_OK(con->EmulateElection());
LOG(INFO) << "Waiting for servers to agree...";
ASSERT_OK(WaitForServersToAgree(MonoDelta::FromSeconds(5),
- ts_map, tablet_peers[0]->tablet_id(), i + 1));
+ ts_map, tablet_replicas[0]->tablet_id(), i + 1));
// Now check that the tablet report reports the correct role for both servers.
for (int replica = 0; replica < kNumReplicas; replica++) {
@@ -184,7 +184,7 @@ TEST_F(TsTabletManagerITest, TestReportNewLeaderOnLeaderChange) {
ReportedTabletPB reported_tablet = report.updated_tablets(0);
ASSERT_TRUE(reported_tablet.has_committed_consensus_state());
- string uuid = tablet_peers[replica]->permanent_uuid();
+ string uuid = tablet_replicas[replica]->permanent_uuid();
RaftPeerPB::Role role = GetConsensusRole(uuid, reported_tablet.committed_consensus_state());
if (replica == new_leader_idx) {
ASSERT_EQ(RaftPeerPB::LEADER, role)
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/master/catalog_manager.cc
----------------------------------------------------------------------
diff --git a/src/kudu/master/catalog_manager.cc b/src/kudu/master/catalog_manager.cc
index a19273c..3c61f84 100644
--- a/src/kudu/master/catalog_manager.cc
+++ b/src/kudu/master/catalog_manager.cc
@@ -232,7 +232,7 @@ using strings::Substitute;
using tablet::TABLET_DATA_DELETED;
using tablet::TABLET_DATA_TOMBSTONED;
using tablet::TabletDataState;
-using tablet::TabletPeer;
+using tablet::TabletReplica;
using tablet::TabletStatePB;
using tserver::TabletServerErrorPB;
@@ -719,7 +719,7 @@ Status CatalogManager::ElectedAsLeaderCb() {
}
Status CatalogManager::WaitUntilCaughtUpAsLeader(const MonoDelta& timeout) {
- ConsensusStatePB cstate = sys_catalog_->tablet_peer()->consensus()->
+ ConsensusStatePB cstate = sys_catalog_->tablet_replica()->consensus()->
ConsensusState(CONSENSUS_CONFIG_COMMITTED);
const string& uuid = master_->fs_manager()->uuid();
if (!cstate.has_leader_uuid() || cstate.leader_uuid() != uuid) {
@@ -729,7 +729,7 @@ Status CatalogManager::WaitUntilCaughtUpAsLeader(const MonoDelta& timeout) {
}
// Wait for all transactions to be committed.
- RETURN_NOT_OK(sys_catalog_->tablet_peer()->transaction_tracker()->WaitForAllToFinish(timeout));
+ RETURN_NOT_OK(sys_catalog_->tablet_replica()->transaction_tracker()->WaitForAllToFinish(timeout));
return Status::OK();
}
@@ -800,7 +800,7 @@ void CatalogManager::VisitTablesAndTabletsTask() {
// Hack to block this function until InitSysCatalogAsync() is finished.
shared_lock<LockType> l(lock_);
}
- const Consensus* consensus = sys_catalog_->tablet_peer()->consensus();
+ const Consensus* consensus = sys_catalog_->tablet_replica()->consensus();
int64_t term = consensus->ConsensusState(CONSENSUS_CONFIG_COMMITTED).current_term();
{
std::lock_guard<simple_spinlock> l(state_lock_);
@@ -977,7 +977,7 @@ RaftPeerPB::Role CatalogManager::Role() const {
{
std::lock_guard<simple_spinlock> l(state_lock_);
if (state_ == kRunning) {
- consensus = sys_catalog_->tablet_peer()->shared_consensus();
+ consensus = sys_catalog_->tablet_replica()->shared_consensus();
}
}
return consensus ? consensus->role() : RaftPeerPB::UNKNOWN_ROLE;
@@ -1026,12 +1026,12 @@ void CatalogManager::Shutdown() {
// call does not return because the underlying Raft indefinitely
// retries to get the response for the submitted operations.
if (sys_catalog_) {
- sys_catalog_->tablet_peer()->consensus()->Shutdown();
+ sys_catalog_->tablet_replica()->consensus()->Shutdown();
}
// Wait for any outstanding ElectedAsLeaderCb tasks to finish.
//
- // Must be done before shutting down the catalog, otherwise its tablet peer
+ // Must be done before shutting down the catalog, otherwise its TabletReplica
// may be destroyed while still in use by the ElectedAsLeaderCb task.
leader_election_pool_->Shutdown();
@@ -2502,8 +2502,8 @@ Status CatalogManager::HandleRaftConfigChanged(
return Status::OK();
}
-Status CatalogManager::GetTabletPeer(const string& tablet_id,
- scoped_refptr<TabletPeer>* tablet_peer) const {
+Status CatalogManager::GetTabletReplica(const string& tablet_id,
+ scoped_refptr<TabletReplica>* replica) const {
// Note: CatalogManager has only one table, 'sys_catalog', with only
// one tablet.
shared_lock<LockType> l(lock_);
@@ -2511,7 +2511,7 @@ Status CatalogManager::GetTabletPeer(const string& tablet_id,
return Status::ServiceUnavailable("Systable not yet initialized");
}
if (sys_catalog_->tablet_id() == tablet_id) {
- *tablet_peer = sys_catalog_->tablet_peer();
+ *replica = sys_catalog_->tablet_replica();
} else {
return Status::NotFound(Substitute("no SysTable exists with tablet_id $0 in CatalogManager",
tablet_id));
@@ -3951,8 +3951,8 @@ void CatalogManager::DumpState(std::ostream* out) const {
std::string CatalogManager::LogPrefix() const {
return Substitute("T $0 P $1: ",
- sys_catalog_->tablet_peer()->tablet_id(),
- sys_catalog_->tablet_peer()->permanent_uuid());
+ sys_catalog_->tablet_replica()->tablet_id(),
+ sys_catalog_->tablet_replica()->permanent_uuid());
}
void CatalogManager::AbortAndWaitForAllTasks(
@@ -3984,7 +3984,7 @@ CatalogManager::ScopedLeaderSharedLock::ScopedLeaderSharedLock(
}
// Check if the catalog manager is the leader.
- ConsensusStatePB cstate = catalog_->sys_catalog_->tablet_peer()->consensus()->
+ ConsensusStatePB cstate = catalog_->sys_catalog_->tablet_replica()->consensus()->
ConsensusState(CONSENSUS_CONFIG_COMMITTED);
string uuid = catalog_->master_->fs_manager()->uuid();
if (PREDICT_FALSE(!cstate.has_leader_uuid() || cstate.leader_uuid() != uuid)) {
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/master/catalog_manager.h
----------------------------------------------------------------------
diff --git a/src/kudu/master/catalog_manager.h b/src/kudu/master/catalog_manager.h
index fe8c4aa..59ffe16 100644
--- a/src/kudu/master/catalog_manager.h
+++ b/src/kudu/master/catalog_manager.h
@@ -33,7 +33,7 @@
#include "kudu/master/master.pb.h"
#include "kudu/master/ts_manager.h"
#include "kudu/server/monitored_task.h"
-#include "kudu/tserver/tablet_peer_lookup.h"
+#include "kudu/tserver/tablet_replica_lookup.h"
#include "kudu/util/cow_object.h"
#include "kudu/util/locks.h"
#include "kudu/util/monotime.h"
@@ -300,7 +300,7 @@ typedef MetadataLock<TableInfo> TableMetadataLock;
// the state of each tablet on a given tablet-server.
//
// Thread-safe.
-class CatalogManager : public tserver::TabletPeerLookupIf {
+class CatalogManager : public tserver::TabletReplicaLookupIf {
public:
// Scoped "shared lock" to serialize master leader elections.
@@ -504,12 +504,12 @@ class CatalogManager : public tserver::TabletPeerLookupIf {
// deleted the specified tablet.
void NotifyTabletDeleteSuccess(const std::string& permanent_uuid, const std::string& tablet_id);
- // Used by ConsensusService to retrieve the TabletPeer for a system
+ // Used by ConsensusService to retrieve the TabletReplica for a system
// table specified by 'tablet_id'.
//
- // See also: TabletPeerLookupIf, ConsensusServiceImpl.
- virtual Status GetTabletPeer(const std::string& tablet_id,
- scoped_refptr<tablet::TabletPeer>* tablet_peer) const override;
+ // See also: TabletReplicaLookupIf, ConsensusServiceImpl.
+ virtual Status GetTabletReplica(const std::string& tablet_id,
+ scoped_refptr<tablet::TabletReplica>* replica) const override;
virtual const NodeInstancePB& NodeInstance() const override;
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/master/sys_catalog.cc
----------------------------------------------------------------------
diff --git a/src/kudu/master/sys_catalog.cc b/src/kudu/master/sys_catalog.cc
index 2d54fcc..8820580 100644
--- a/src/kudu/master/sys_catalog.cc
+++ b/src/kudu/master/sys_catalog.cc
@@ -71,7 +71,7 @@ using kudu::consensus::RaftPeerPB;
using kudu::log::Log;
using kudu::tablet::LatchTransactionCompletionCallback;
using kudu::tablet::Tablet;
-using kudu::tablet::TabletPeer;
+using kudu::tablet::TabletReplica;
using kudu::tablet::TabletStatusListener;
using kudu::tserver::WriteRequestPB;
using kudu::tserver::WriteResponsePB;
@@ -107,8 +107,8 @@ SysCatalogTable::~SysCatalogTable() {
}
void SysCatalogTable::Shutdown() {
- if (tablet_peer_) {
- tablet_peer_->Shutdown();
+ if (tablet_replica_) {
+ tablet_replica_->Shutdown();
}
apply_pool_->Shutdown();
}
@@ -254,8 +254,8 @@ Status SysCatalogTable::CreateDistributedConfig(const MasterOptions& options,
}
void SysCatalogTable::SysCatalogStateChanged(const string& tablet_id, const string& reason) {
- CHECK_EQ(tablet_id, tablet_peer_->tablet_id());
- scoped_refptr<consensus::Consensus> consensus = tablet_peer_->shared_consensus();
+ CHECK_EQ(tablet_id, tablet_replica_->tablet_id());
+ scoped_refptr<consensus::Consensus> consensus = tablet_replica_->shared_consensus();
if (!consensus) {
LOG_WITH_PREFIX(WARNING) << "Received notification of tablet state change "
<< "but tablet no longer running. Tablet ID: "
@@ -265,7 +265,7 @@ void SysCatalogTable::SysCatalogStateChanged(const string& tablet_id, const stri
consensus::ConsensusStatePB cstate = consensus->ConsensusState(CONSENSUS_CONFIG_COMMITTED);
LOG_WITH_PREFIX(INFO) << "SysCatalogTable state changed. Reason: " << reason << ". "
<< "Latest consensus state: " << SecureShortDebugString(cstate);
- RaftPeerPB::Role new_role = GetConsensusRole(tablet_peer_->permanent_uuid(), cstate);
+ RaftPeerPB::Role new_role = GetConsensusRole(tablet_replica_->permanent_uuid(), cstate);
LOG_WITH_PREFIX(INFO) << "This master's current role is: "
<< RaftPeerPB::Role_Name(new_role);
if (new_role == RaftPeerPB::LEADER) {
@@ -286,40 +286,40 @@ Status SysCatalogTable::SetupTablet(const scoped_refptr<tablet::TabletMetadata>&
// TODO: handle crash mid-creation of tablet? do we ever end up with a
// partially created tablet here?
- tablet_peer_.reset(new TabletPeer(
+ tablet_replica_.reset(new TabletReplica(
metadata,
local_peer_pb_,
apply_pool_.get(),
Bind(&SysCatalogTable::SysCatalogStateChanged, Unretained(this), metadata->tablet_id())));
consensus::ConsensusBootstrapInfo consensus_info;
- tablet_peer_->SetBootstrapping();
+ tablet_replica_->SetBootstrapping();
RETURN_NOT_OK(BootstrapTablet(metadata,
scoped_refptr<server::Clock>(master_->clock()),
master_->mem_tracker(),
scoped_refptr<rpc::ResultTracker>(),
metric_registry_,
- implicit_cast<TabletStatusListener*>(tablet_peer_.get()),
+ implicit_cast<TabletStatusListener*>(tablet_replica_.get()),
&tablet,
&log,
- tablet_peer_->log_anchor_registry(),
+ tablet_replica_->log_anchor_registry(),
&consensus_info));
// TODO: Do we have a setSplittable(false) or something from the outside is
// handling split in the TS?
- RETURN_NOT_OK_PREPEND(tablet_peer_->Init(tablet,
+ RETURN_NOT_OK_PREPEND(tablet_replica_->Init(tablet,
scoped_refptr<server::Clock>(master_->clock()),
master_->messenger(),
scoped_refptr<rpc::ResultTracker>(),
log,
tablet->GetMetricEntity()),
- "Failed to Init() TabletPeer");
+ "Failed to Init() TabletReplica");
- RETURN_NOT_OK_PREPEND(tablet_peer_->Start(consensus_info),
- "Failed to Start() TabletPeer");
+ RETURN_NOT_OK_PREPEND(tablet_replica_->Start(consensus_info),
+ "Failed to Start() TabletReplica");
- tablet_peer_->RegisterMaintenanceOps(master_->maintenance_manager());
+ tablet_replica_->RegisterMaintenanceOps(master_->maintenance_manager());
const Schema* schema = tablet->schema();
schema_ = SchemaBuilder(*schema).BuildWithoutIds();
@@ -329,8 +329,8 @@ Status SysCatalogTable::SetupTablet(const scoped_refptr<tablet::TabletMetadata>&
std::string SysCatalogTable::LogPrefix() const {
return Substitute("T $0 P $1 [$2]: ",
- tablet_peer_->tablet_id(),
- tablet_peer_->permanent_uuid(),
+ tablet_replica_->tablet_id(),
+ tablet_replica_->permanent_uuid(),
table_name());
}
@@ -338,7 +338,7 @@ Status SysCatalogTable::WaitUntilRunning() {
TRACE_EVENT0("master", "SysCatalogTable::WaitUntilRunning");
int seconds_waited = 0;
while (true) {
- Status status = tablet_peer_->WaitUntilConsensusRunning(MonoDelta::FromSeconds(1));
+ Status status = tablet_replica_->WaitUntilConsensusRunning(MonoDelta::FromSeconds(1));
seconds_waited++;
if (status.ok()) {
LOG_WITH_PREFIX(INFO) << "configured and running, proceeding with master startup.";
@@ -363,13 +363,13 @@ Status SysCatalogTable::SyncWrite(const WriteRequestPB *req, WriteResponsePB *re
gscoped_ptr<tablet::TransactionCompletionCallback> txn_callback(
new LatchTransactionCompletionCallback<WriteResponsePB>(&latch, resp));
unique_ptr<tablet::WriteTransactionState> tx_state(
- new tablet::WriteTransactionState(tablet_peer_.get(),
+ new tablet::WriteTransactionState(tablet_replica_.get(),
req,
nullptr, // No RequestIdPB
resp));
tx_state->set_completion_callback(std::move(txn_callback));
- RETURN_NOT_OK(tablet_peer_->SubmitWrite(std::move(tx_state)));
+ RETURN_NOT_OK(tablet_replica_->SubmitWrite(std::move(tx_state)));
latch.Wait();
if (resp->has_error()) {
@@ -525,7 +525,7 @@ Status SysCatalogTable::ProcessRows(
spec.AddPredicate(pred);
gscoped_ptr<RowwiseIterator> iter;
- RETURN_NOT_OK(tablet_peer_->tablet()->NewRowIterator(schema_, &iter));
+ RETURN_NOT_OK(tablet_replica_->tablet()->NewRowIterator(schema_, &iter));
RETURN_NOT_OK(iter->Init(&spec));
Arena arena(32 * 1024, 256 * 1024);
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/master/sys_catalog.h
----------------------------------------------------------------------
diff --git a/src/kudu/master/sys_catalog.h b/src/kudu/master/sys_catalog.h
index 11e92cd..4197288 100644
--- a/src/kudu/master/sys_catalog.h
+++ b/src/kudu/master/sys_catalog.h
@@ -24,7 +24,7 @@
#include "kudu/consensus/metadata.pb.h"
#include "kudu/master/master.pb.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/util/status.h"
namespace kudu {
@@ -113,13 +113,13 @@ class SysCatalogTable {
~SysCatalogTable();
- // Allow for orderly shutdown of tablet peer, etc.
+ // Allow for orderly shutdown of TabletReplica, etc.
void Shutdown();
- // Load the Metadata from disk, and initialize the TabletPeer for the sys-table
+ // Load the Metadata from disk, and initialize the TabletReplica for the sys-table
Status Load(FsManager *fs_manager);
- // Create the new Metadata and initialize the TabletPeer for the sys-table.
+ // Create the new Metadata and initialize the TabletReplica for the sys-table.
Status CreateNew(FsManager *fs_manager);
// Perform a series of table/tablet actions in one WriteTransaction.
@@ -183,12 +183,12 @@ class SysCatalogTable {
Status CreateDistributedConfig(const MasterOptions& options,
consensus::RaftConfigPB* committed_config);
- const scoped_refptr<tablet::TabletPeer>& tablet_peer() const {
- return tablet_peer_;
+ const scoped_refptr<tablet::TabletReplica>& tablet_replica() const {
+ return tablet_replica_;
}
std::string tablet_id() const {
- return tablet_peer_->tablet_id();
+ return tablet_replica_->tablet_id();
}
// Conventional "T xxx P xxxx..." prefix for logging.
@@ -239,7 +239,7 @@ class SysCatalogTable {
// Only useful for tests.
static const char* const kInjectedFailureStatusMsg;
- // Table schema, without IDs, used to send messages to the TabletPeer
+ // Table schema, without IDs, used to send messages to the TabletReplica
Schema schema_;
Schema key_schema_;
@@ -247,7 +247,7 @@ class SysCatalogTable {
gscoped_ptr<ThreadPool> apply_pool_;
- scoped_refptr<tablet::TabletPeer> tablet_peer_;
+ scoped_refptr<tablet::TabletReplica> tablet_replica_;
Master* master_;
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/CMakeLists.txt b/src/kudu/tablet/CMakeLists.txt
index 49fafef..c54ba43 100644
--- a/src/kudu/tablet/CMakeLists.txt
+++ b/src/kudu/tablet/CMakeLists.txt
@@ -20,8 +20,8 @@ set(TABLET_SRCS
tablet_bootstrap.cc
tablet_metrics.cc
tablet_mm_ops.cc
- tablet_peer_mm_ops.cc
- tablet_peer.cc
+ tablet_replica_mm_ops.cc
+ tablet_replica.cc
transactions/transaction.cc
transactions/alter_schema_transaction.cc
transactions/transaction_driver.cc
@@ -118,7 +118,7 @@ ADD_KUDU_TEST(mt-rowset_delta_compaction-test)
ADD_KUDU_TEST(major_delta_compaction-test)
ADD_KUDU_TEST(transactions/transaction_tracker-test)
ADD_KUDU_TEST(tablet_history_gc-test)
-ADD_KUDU_TEST(tablet_peer-test)
+ADD_KUDU_TEST(tablet_replica-test)
ADD_KUDU_TEST(tablet_random_access-test)
ADD_KUDU_TEST(tablet_throttle-test)
ADD_KUDU_TEST(tablet_mm_ops-test)
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/local_tablet_writer.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/local_tablet_writer.h b/src/kudu/tablet/local_tablet_writer.h
index e0d3371..6bc3f6e 100644
--- a/src/kudu/tablet/local_tablet_writer.h
+++ b/src/kudu/tablet/local_tablet_writer.h
@@ -32,7 +32,7 @@ namespace kudu {
namespace tablet {
// Helper class to write directly into a local tablet, without going
-// through TabletPeer, consensus, etc.
+// through TabletReplica, consensus, etc.
//
// This is useful for unit-testing the Tablet code paths with no consensus
// implementation or thread pools.
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/metadata.proto
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/metadata.proto b/src/kudu/tablet/metadata.proto
index fc9b9dc..7acd140 100644
--- a/src/kudu/tablet/metadata.proto
+++ b/src/kudu/tablet/metadata.proto
@@ -125,7 +125,7 @@ message TabletSuperBlockPB {
}
// The enum of tablet states.
-// Tablet states are sent in TabletReports and kept in TabletPeer.
+// Tablet states are sent in TabletReports and kept in TabletReplica.
enum TabletStatePB {
UNKNOWN = 999;
@@ -140,7 +140,7 @@ enum TabletStatePB {
// state Peers are available for client RPCs.
RUNNING = 1;
- // The tablet failed to for some reason. TabletPeer::error() will return
+ // The tablet failed to for some reason. TabletReplica::error() will return
// the reason for the failure.
FAILED = 2;
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/tablet-harness.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet-harness.h b/src/kudu/tablet/tablet-harness.h
index fd09c5a..44159d5 100644
--- a/src/kudu/tablet/tablet-harness.h
+++ b/src/kudu/tablet/tablet-harness.h
@@ -14,8 +14,8 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-#ifndef KUDU_TABLET_TABLET_PEER_HARNESS_H
-#define KUDU_TABLET_TABLET_PEER_HARNESS_H
+#ifndef KUDU_TABLET_TABLET_REPLICA_HARNESS_H
+#define KUDU_TABLET_TABLET_REPLICA_HARNESS_H
#include <memory>
#include <string>
@@ -155,4 +155,4 @@ class TabletHarness {
} // namespace tablet
} // namespace kudu
-#endif /* KUDU_TABLET_TABLET_PEER_HARNESS_H */
+#endif /* KUDU_TABLET_TABLET_REPLICA_HARNESS_H */
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/tablet.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet.h b/src/kudu/tablet/tablet.h
index a7c1d84..4c5b6e5 100644
--- a/src/kudu/tablet/tablet.h
+++ b/src/kudu/tablet/tablet.h
@@ -395,7 +395,7 @@ class Tablet {
private:
friend class Iterator;
- friend class TabletPeerTest;
+ friend class TabletReplicaTest;
FRIEND_TEST(TestTablet, TestGetReplaySizeForIndex);
Status FlushUnlocked();
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/tablet_bootstrap.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet_bootstrap.cc b/src/kudu/tablet/tablet_bootstrap.cc
index 04eea5f..47775b9 100644
--- a/src/kudu/tablet/tablet_bootstrap.cc
+++ b/src/kudu/tablet/tablet_bootstrap.cc
@@ -48,7 +48,7 @@
#include "kudu/tablet/lock_manager.h"
#include "kudu/tablet/row_op.h"
#include "kudu/tablet/tablet.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tablet/transactions/alter_schema_transaction.h"
#include "kudu/tablet/transactions/write_transaction.h"
#include "kudu/util/debug/trace_event.h"
@@ -320,7 +320,7 @@ class TabletBootstrap {
// Return a log prefix string in the standard "T xxx P yyy" format.
string LogPrefix() const;
- // Report a status message in the WAL as well as update the tablet peer's
+ // Report a status message in the WAL as well as update the TabletReplica's
// status.
void StatusMessage(const string& status);
[3/5] kudu git commit: Rename TabletPeer to TabletReplica
Posted by mp...@apache.org.
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/tablet_replica-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet_replica-test.cc b/src/kudu/tablet/tablet_replica-test.cc
new file mode 100644
index 0000000..c48da6a
--- /dev/null
+++ b/src/kudu/tablet/tablet_replica-test.cc
@@ -0,0 +1,565 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <glog/logging.h>
+#include <gtest/gtest.h>
+
+#include "kudu/common/partial_row.h"
+#include "kudu/common/timestamp.h"
+#include "kudu/common/wire_protocol.h"
+#include "kudu/common/wire_protocol-test-util.h"
+#include "kudu/consensus/consensus_meta.h"
+#include "kudu/consensus/log.h"
+#include "kudu/consensus/log_reader.h"
+#include "kudu/consensus/log_util.h"
+#include "kudu/consensus/opid_util.h"
+#include "kudu/gutil/gscoped_ptr.h"
+#include "kudu/gutil/macros.h"
+#include "kudu/rpc/messenger.h"
+#include "kudu/server/clock.h"
+#include "kudu/server/logical_clock.h"
+#include "kudu/tablet/transactions/transaction.h"
+#include "kudu/tablet/transactions/transaction_driver.h"
+#include "kudu/tablet/transactions/write_transaction.h"
+#include "kudu/tablet/tablet_replica.h"
+#include "kudu/tablet/tablet_replica_mm_ops.h"
+#include "kudu/tablet/tablet-test-util.h"
+#include "kudu/tserver/tserver.pb.h"
+#include "kudu/util/maintenance_manager.h"
+#include "kudu/util/metrics.h"
+#include "kudu/util/pb_util.h"
+#include "kudu/util/test_macros.h"
+#include "kudu/util/test_util.h"
+#include "kudu/util/threadpool.h"
+
+METRIC_DECLARE_entity(tablet);
+
+DECLARE_int32(flush_threshold_mb);
+
+namespace kudu {
+namespace tablet {
+
+using consensus::CommitMsg;
+using consensus::Consensus;
+using consensus::ConsensusBootstrapInfo;
+using consensus::ConsensusMetadata;
+using consensus::MakeOpId;
+using consensus::MinimumOpId;
+using consensus::OpId;
+using consensus::OpIdEquals;
+using consensus::RaftPeerPB;
+using consensus::WRITE_OP;
+using log::Log;
+using log::LogAnchorRegistry;
+using log::LogOptions;
+using rpc::Messenger;
+using server::Clock;
+using server::LogicalClock;
+using std::shared_ptr;
+using std::string;
+using std::unique_ptr;
+using strings::Substitute;
+using tserver::WriteRequestPB;
+using tserver::WriteResponsePB;
+
+static Schema GetTestSchema() {
+ return Schema({ ColumnSchema("key", INT32) }, 1);
+}
+
+class TabletReplicaTest : public KuduTabletTest {
+ public:
+ TabletReplicaTest()
+ : KuduTabletTest(GetTestSchema()),
+ insert_counter_(0),
+ delete_counter_(0) {
+ }
+
+ virtual void SetUp() OVERRIDE {
+ KuduTabletTest::SetUp();
+
+ ASSERT_OK(ThreadPoolBuilder("apply").Build(&apply_pool_));
+
+ rpc::MessengerBuilder builder(CURRENT_TEST_NAME());
+ ASSERT_OK(builder.Build(&messenger_));
+
+ metric_entity_ = METRIC_ENTITY_tablet.Instantiate(&metric_registry_, "test-tablet");
+
+ RaftPeerPB config_peer;
+ config_peer.set_permanent_uuid(tablet()->metadata()->fs_manager()->uuid());
+ config_peer.mutable_last_known_addr()->set_host("0.0.0.0");
+ config_peer.mutable_last_known_addr()->set_port(0);
+ config_peer.set_member_type(RaftPeerPB::VOTER);
+
+ // "Bootstrap" and start the TabletReplica.
+ tablet_replica_.reset(
+ new TabletReplica(make_scoped_refptr(tablet()->metadata()),
+ config_peer,
+ apply_pool_.get(),
+ Bind(&TabletReplicaTest::TabletReplicaStateChangedCallback,
+ Unretained(this),
+ tablet()->tablet_id())));
+
+ // Make TabletReplica use the same LogAnchorRegistry as the Tablet created by the harness.
+ // TODO: Refactor TabletHarness to allow taking a LogAnchorRegistry, while also providing
+ // TabletMetadata for consumption by TabletReplica before Tablet is instantiated.
+ tablet_replica_->log_anchor_registry_ = tablet()->log_anchor_registry_;
+
+ RaftConfigPB config;
+ config.add_peers()->CopyFrom(config_peer);
+ config.set_opid_index(consensus::kInvalidOpIdIndex);
+
+ unique_ptr<ConsensusMetadata> cmeta;
+ ASSERT_OK(ConsensusMetadata::Create(tablet()->metadata()->fs_manager(),
+ tablet()->tablet_id(),
+ tablet()->metadata()->fs_manager()->uuid(),
+ config,
+ consensus::kMinimumTerm, &cmeta));
+
+ scoped_refptr<Log> log;
+ ASSERT_OK(Log::Open(LogOptions(), fs_manager(), tablet()->tablet_id(),
+ *tablet()->schema(), tablet()->metadata()->schema_version(),
+ metric_entity_.get(), &log));
+
+ tablet_replica_->SetBootstrapping();
+ ASSERT_OK(tablet_replica_->Init(tablet(),
+ clock(),
+ messenger_,
+ scoped_refptr<rpc::ResultTracker>(),
+ log,
+ metric_entity_));
+ }
+
+ Status StartPeer(const ConsensusBootstrapInfo& info) {
+ const MonoDelta kTimeout = MonoDelta::FromSeconds(10);
+ RETURN_NOT_OK(tablet_replica_->Start(info));
+ RETURN_NOT_OK(tablet_replica_->consensus()->WaitUntilLeaderForTests(kTimeout));
+ return Status::OK();
+ }
+
+ void TabletReplicaStateChangedCallback(const string& tablet_id, const string& reason) {
+ LOG(INFO) << "Tablet replica state changed for tablet " << tablet_id << ". Reason: " << reason;
+ }
+
+ virtual void TearDown() OVERRIDE {
+ tablet_replica_->Shutdown();
+ apply_pool_->Shutdown();
+ KuduTabletTest::TearDown();
+ }
+
+ protected:
+ // Generate monotonic sequence of key column integers.
+ Status GenerateSequentialInsertRequest(WriteRequestPB* write_req) {
+ Schema schema(GetTestSchema());
+ write_req->set_tablet_id(tablet()->tablet_id());
+ CHECK_OK(SchemaToPB(schema, write_req->mutable_schema()));
+
+ KuduPartialRow row(&schema);
+ CHECK_OK(row.SetInt32("key", insert_counter_++));
+
+ RowOperationsPBEncoder enc(write_req->mutable_row_operations());
+ enc.Add(RowOperationsPB::INSERT, row);
+ return Status::OK();
+ }
+
+ // Generate monotonic sequence of deletions, starting with 0.
+ // Will assert if you try to delete more rows than you inserted.
+ Status GenerateSequentialDeleteRequest(WriteRequestPB* write_req) {
+ CHECK_LT(delete_counter_, insert_counter_);
+ Schema schema(GetTestSchema());
+ write_req->set_tablet_id(tablet()->tablet_id());
+ CHECK_OK(SchemaToPB(schema, write_req->mutable_schema()));
+
+ KuduPartialRow row(&schema);
+ CHECK_OK(row.SetInt32("key", delete_counter_++));
+
+ RowOperationsPBEncoder enc(write_req->mutable_row_operations());
+ enc.Add(RowOperationsPB::DELETE, row);
+ return Status::OK();
+ }
+
+ Status ExecuteWriteAndRollLog(TabletReplica* tablet_replica, const WriteRequestPB& req) {
+ gscoped_ptr<WriteResponsePB> resp(new WriteResponsePB());
+ unique_ptr<WriteTransactionState> tx_state(new WriteTransactionState(tablet_replica,
+ &req,
+ nullptr, // No RequestIdPB
+ resp.get()));
+
+ CountDownLatch rpc_latch(1);
+ tx_state->set_completion_callback(gscoped_ptr<TransactionCompletionCallback>(
+ new LatchTransactionCompletionCallback<WriteResponsePB>(&rpc_latch, resp.get())));
+
+ CHECK_OK(tablet_replica->SubmitWrite(std::move(tx_state)));
+ rpc_latch.Wait();
+ CHECK(!resp->has_error())
+ << "\nReq:\n" << SecureDebugString(req) << "Resp:\n" << SecureDebugString(*resp);
+
+ // Roll the log after each write.
+ // Usually the append thread does the roll and no additional sync is required. However in
+ // this test the thread that is appending is not the same thread that is rolling the log
+ // so we must make sure the Log's queue is flushed before we roll or we might have a race
+ // between the appender thread and the thread executing the test.
+ CHECK_OK(tablet_replica->log_->WaitUntilAllFlushed());
+ CHECK_OK(tablet_replica->log_->AllocateSegmentAndRollOver());
+ return Status::OK();
+ }
+
+ // Execute insert requests and roll log after each one.
+ Status ExecuteInsertsAndRollLogs(int num_inserts) {
+ for (int i = 0; i < num_inserts; i++) {
+ gscoped_ptr<WriteRequestPB> req(new WriteRequestPB());
+ RETURN_NOT_OK(GenerateSequentialInsertRequest(req.get()));
+ RETURN_NOT_OK(ExecuteWriteAndRollLog(tablet_replica_.get(), *req));
+ }
+
+ return Status::OK();
+ }
+
+ // Execute delete requests and roll log after each one.
+ Status ExecuteDeletesAndRollLogs(int num_deletes) {
+ for (int i = 0; i < num_deletes; i++) {
+ gscoped_ptr<WriteRequestPB> req(new WriteRequestPB());
+ CHECK_OK(GenerateSequentialDeleteRequest(req.get()));
+ CHECK_OK(ExecuteWriteAndRollLog(tablet_replica_.get(), *req));
+ }
+
+ return Status::OK();
+ }
+
+ void AssertNoLogAnchors() {
+ // Make sure that there are no registered anchors in the registry
+ CHECK_EQ(0, tablet_replica_->log_anchor_registry()->GetAnchorCountForTests());
+ }
+
+ // Assert that the Log GC() anchor is earlier than the latest OpId in the Log.
+ void AssertLogAnchorEarlierThanLogLatest() {
+ log::RetentionIndexes retention = tablet_replica_->GetRetentionIndexes();
+ OpId last_log_opid;
+ tablet_replica_->log_->GetLatestEntryOpId(&last_log_opid);
+ CHECK_LT(retention.for_durability, last_log_opid.index())
+ << "Expected valid log anchor, got earliest opid: " << retention.for_durability
+ << " (expected any value earlier than last log id: " << SecureShortDebugString(last_log_opid)
+ << ")";
+ }
+
+ // We disable automatic log GC. Don't leak those changes.
+ google::FlagSaver flag_saver_;
+
+ int32_t insert_counter_;
+ int32_t delete_counter_;
+ MetricRegistry metric_registry_;
+ scoped_refptr<MetricEntity> metric_entity_;
+ shared_ptr<Messenger> messenger_;
+ scoped_refptr<TabletReplica> tablet_replica_;
+ gscoped_ptr<ThreadPool> apply_pool_;
+};
+
+// A Transaction that waits on the apply_continue latch inside of Apply().
+class DelayedApplyTransaction : public WriteTransaction {
+ public:
+ DelayedApplyTransaction(CountDownLatch* apply_started,
+ CountDownLatch* apply_continue,
+ unique_ptr<WriteTransactionState> state)
+ : WriteTransaction(std::move(state), consensus::LEADER),
+ apply_started_(DCHECK_NOTNULL(apply_started)),
+ apply_continue_(DCHECK_NOTNULL(apply_continue)) {
+ }
+
+ virtual Status Apply(gscoped_ptr<CommitMsg>* commit_msg) OVERRIDE {
+ apply_started_->CountDown();
+ LOG(INFO) << "Delaying apply...";
+ apply_continue_->Wait();
+ LOG(INFO) << "Apply proceeding";
+ return WriteTransaction::Apply(commit_msg);
+ }
+
+ private:
+ CountDownLatch* apply_started_;
+ CountDownLatch* apply_continue_;
+ DISALLOW_COPY_AND_ASSIGN(DelayedApplyTransaction);
+};
+
+// Ensure that Log::GC() doesn't delete logs when the MRS has an anchor.
+TEST_F(TabletReplicaTest, TestMRSAnchorPreventsLogGC) {
+ ConsensusBootstrapInfo info;
+ ASSERT_OK(StartPeer(info));
+
+ Log* log = tablet_replica_->log_.get();
+ int32_t num_gced;
+
+ AssertNoLogAnchors();
+
+ log::SegmentSequence segments;
+ ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
+
+ ASSERT_EQ(1, segments.size());
+ ASSERT_OK(ExecuteInsertsAndRollLogs(3));
+ ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
+ ASSERT_EQ(4, segments.size());
+
+ AssertLogAnchorEarlierThanLogLatest();
+ ASSERT_GT(tablet_replica_->log_anchor_registry()->GetAnchorCountForTests(), 0);
+
+ // Ensure nothing gets deleted.
+ log::RetentionIndexes retention = tablet_replica_->GetRetentionIndexes();
+ ASSERT_OK(log->GC(retention, &num_gced));
+ ASSERT_EQ(0, num_gced) << "earliest needed: " << retention.for_durability;
+
+ // Flush MRS as needed to ensure that we don't have OpId anchors in the MRS.
+ tablet_replica_->tablet()->Flush();
+ AssertNoLogAnchors();
+
+ // The first two segments should be deleted.
+ // The last is anchored due to the commit in the last segment being the last
+ // OpId in the log.
+ retention = tablet_replica_->GetRetentionIndexes();
+ ASSERT_OK(log->GC(retention, &num_gced));
+ ASSERT_EQ(2, num_gced) << "earliest needed: " << retention.for_durability;
+ ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
+ ASSERT_EQ(2, segments.size());
+}
+
+// Ensure that Log::GC() doesn't delete logs when the DMS has an anchor.
+TEST_F(TabletReplicaTest, TestDMSAnchorPreventsLogGC) {
+ ConsensusBootstrapInfo info;
+ ASSERT_OK(StartPeer(info));
+
+ Log* log = tablet_replica_->log_.get();
+ int32_t num_gced;
+
+ AssertNoLogAnchors();
+
+ log::SegmentSequence segments;
+ ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
+
+ ASSERT_EQ(1, segments.size());
+ ASSERT_OK(ExecuteInsertsAndRollLogs(2));
+ ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
+ ASSERT_EQ(3, segments.size());
+
+ // Flush MRS & GC log so the next mutation goes into a DMS.
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
+ log::RetentionIndexes retention = tablet_replica_->GetRetentionIndexes();
+ ASSERT_OK(log->GC(retention, &num_gced));
+ // We will only GC 1, and have 1 left because the earliest needed OpId falls
+ // back to the latest OpId written to the Log if no anchors are set.
+ ASSERT_EQ(1, num_gced);
+ ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
+ ASSERT_EQ(2, segments.size());
+ AssertNoLogAnchors();
+
+ OpId id;
+ log->GetLatestEntryOpId(&id);
+ LOG(INFO) << "Before: " << SecureShortDebugString(id);
+
+
+ // We currently have no anchors and the last operation in the log is 0.3
+ // Before the below was ExecuteDeletesAndRollLogs(1) but that was breaking
+ // what I think is a wrong assertion.
+ // I.e. since 0.4 is the last operation that we know is in memory 0.4 is the
+ // last anchor we expect _and_ it's the last op in the log.
+ // Only if we apply two operations is the last anchored operation and the
+ // last operation in the log different.
+
+ // Execute a mutation.
+ ASSERT_OK(ExecuteDeletesAndRollLogs(2));
+ AssertLogAnchorEarlierThanLogLatest();
+ ASSERT_GT(tablet_replica_->log_anchor_registry()->GetAnchorCountForTests(), 0);
+ ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
+ ASSERT_EQ(4, segments.size());
+
+ // Execute another couple inserts, but Flush it so it doesn't anchor.
+ ASSERT_OK(ExecuteInsertsAndRollLogs(2));
+ ASSERT_OK(tablet_replica_->tablet()->Flush());
+ ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
+ ASSERT_EQ(6, segments.size());
+
+ // Ensure the delta and last insert remain in the logs, anchored by the delta.
+ // Note that this will allow GC of the 2nd insert done above.
+ retention = tablet_replica_->GetRetentionIndexes();
+ ASSERT_OK(log->GC(retention, &num_gced));
+ ASSERT_EQ(1, num_gced);
+ ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
+ ASSERT_EQ(5, segments.size());
+
+ // Flush DMS to release the anchor.
+ tablet_replica_->tablet()->FlushBiggestDMS();
+
+ // Verify no anchors after Flush().
+ AssertNoLogAnchors();
+
+ // We should only hang onto one segment due to no anchors.
+ // The last log OpId is the commit in the last segment, so it only anchors
+ // that segment, not the previous, because it's not the first OpId in the
+ // segment.
+ retention = tablet_replica_->GetRetentionIndexes();
+ ASSERT_OK(log->GC(retention, &num_gced));
+ ASSERT_EQ(3, num_gced);
+ ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
+ ASSERT_EQ(2, segments.size());
+}
+
+// Ensure that Log::GC() doesn't compact logs with OpIds of active transactions.
+TEST_F(TabletReplicaTest, TestActiveTransactionPreventsLogGC) {
+ ConsensusBootstrapInfo info;
+ ASSERT_OK(StartPeer(info));
+
+ Log* log = tablet_replica_->log_.get();
+ int32_t num_gced;
+
+ AssertNoLogAnchors();
+
+ log::SegmentSequence segments;
+ ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
+
+ ASSERT_EQ(1, segments.size());
+ ASSERT_OK(ExecuteInsertsAndRollLogs(4));
+ ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
+ ASSERT_EQ(5, segments.size());
+
+ // Flush MRS as needed to ensure that we don't have OpId anchors in the MRS.
+ ASSERT_EQ(1, tablet_replica_->log_anchor_registry()->GetAnchorCountForTests());
+ tablet_replica_->tablet()->Flush();
+
+ // Verify no anchors after Flush().
+ AssertNoLogAnchors();
+
+ // Now create a long-lived Transaction that hangs during Apply().
+ // Allow other transactions to go through. Logs should be populated, but the
+ // long-lived Transaction should prevent the log from being deleted since it
+ // is in-flight.
+ CountDownLatch rpc_latch(1);
+ CountDownLatch apply_started(1);
+ CountDownLatch apply_continue(1);
+ gscoped_ptr<WriteRequestPB> req(new WriteRequestPB());
+ gscoped_ptr<WriteResponsePB> resp(new WriteResponsePB());
+ {
+ // Long-running mutation.
+ ASSERT_OK(GenerateSequentialDeleteRequest(req.get()));
+ unique_ptr<WriteTransactionState> tx_state(new WriteTransactionState(tablet_replica_.get(),
+ req.get(),
+ nullptr, // No RequestIdPB
+ resp.get()));
+
+ tx_state->set_completion_callback(gscoped_ptr<TransactionCompletionCallback>(
+ new LatchTransactionCompletionCallback<WriteResponsePB>(&rpc_latch, resp.get())));
+
+ gscoped_ptr<DelayedApplyTransaction> transaction(
+ new DelayedApplyTransaction(&apply_started,
+ &apply_continue,
+ std::move(tx_state)));
+
+ scoped_refptr<TransactionDriver> driver;
+ ASSERT_OK(tablet_replica_->NewLeaderTransactionDriver(transaction.PassAs<Transaction>(),
+ &driver));
+
+ ASSERT_OK(driver->ExecuteAsync());
+ apply_started.Wait();
+ ASSERT_TRUE(driver->GetOpId().IsInitialized())
+ << "By the time a transaction is applied, it should have an Opid";
+ // The apply will hang until we CountDown() the continue latch.
+ // Now, roll the log. Below, we execute a few more insertions with rolling.
+ ASSERT_OK(log->AllocateSegmentAndRollOver());
+ }
+
+ ASSERT_EQ(1, tablet_replica_->txn_tracker_.GetNumPendingForTests());
+ // The log anchor is currently equal to the latest OpId written to the Log
+ // because we are delaying the Commit message with the CountDownLatch.
+
+ // GC the first four segments created by the inserts.
+ log::RetentionIndexes retention = tablet_replica_->GetRetentionIndexes();
+ ASSERT_OK(log->GC(retention, &num_gced));
+ ASSERT_EQ(4, num_gced);
+ ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
+ ASSERT_EQ(2, segments.size());
+
+ // We use mutations here, since an MRS Flush() quiesces the tablet, and we
+ // want to ensure the only thing "anchoring" is the TransactionTracker.
+ ASSERT_OK(ExecuteDeletesAndRollLogs(3));
+ ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
+ ASSERT_EQ(5, segments.size());
+ ASSERT_EQ(1, tablet_replica_->log_anchor_registry()->GetAnchorCountForTests());
+ tablet_replica_->tablet()->FlushBiggestDMS();
+ ASSERT_EQ(0, tablet_replica_->log_anchor_registry()->GetAnchorCountForTests());
+ ASSERT_EQ(1, tablet_replica_->txn_tracker_.GetNumPendingForTests());
+
+ AssertLogAnchorEarlierThanLogLatest();
+
+ // Try to GC(), nothing should be deleted due to the in-flight transaction.
+ retention = tablet_replica_->GetRetentionIndexes();
+ ASSERT_OK(log->GC(retention, &num_gced));
+ ASSERT_EQ(0, num_gced);
+ ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
+ ASSERT_EQ(5, segments.size());
+
+ // Now we release the transaction and wait for everything to complete.
+ // We fully quiesce and flush, which should release all anchors.
+ ASSERT_EQ(1, tablet_replica_->txn_tracker_.GetNumPendingForTests());
+ apply_continue.CountDown();
+ rpc_latch.Wait();
+ tablet_replica_->txn_tracker_.WaitForAllToFinish();
+ ASSERT_EQ(0, tablet_replica_->txn_tracker_.GetNumPendingForTests());
+ tablet_replica_->tablet()->FlushBiggestDMS();
+ AssertNoLogAnchors();
+
+ // All should be deleted except the two last segments.
+ retention = tablet_replica_->GetRetentionIndexes();
+ ASSERT_OK(log->GC(retention, &num_gced));
+ ASSERT_EQ(3, num_gced);
+ ASSERT_OK(log->reader()->GetSegmentsSnapshot(&segments));
+ ASSERT_EQ(2, segments.size());
+}
+
+TEST_F(TabletReplicaTest, TestGCEmptyLog) {
+ ConsensusBootstrapInfo info;
+ tablet_replica_->Start(info);
+ // We don't wait on consensus on purpose.
+ ASSERT_OK(tablet_replica_->RunLogGC());
+}
+
+TEST_F(TabletReplicaTest, TestFlushOpsPerfImprovements) {
+ FLAGS_flush_threshold_mb = 64;
+
+ MaintenanceOpStats stats;
+
+ // Just on the threshold and not enough time has passed for a time-based flush.
+ stats.set_ram_anchored(64 * 1024 * 1024);
+ FlushOpPerfImprovementPolicy::SetPerfImprovementForFlush(&stats, 1);
+ ASSERT_EQ(0.0, stats.perf_improvement());
+ stats.Clear();
+
+ // Just on the threshold and enough time has passed, we'll have a low improvement.
+ stats.set_ram_anchored(64 * 1024 * 1024);
+ FlushOpPerfImprovementPolicy::SetPerfImprovementForFlush(&stats, 3 * 60 * 1000);
+ ASSERT_GT(stats.perf_improvement(), 0.01);
+ stats.Clear();
+
+ // Way over the threshold, number is much higher than 1.
+ stats.set_ram_anchored(128 * 1024 * 1024);
+ FlushOpPerfImprovementPolicy::SetPerfImprovementForFlush(&stats, 1);
+ ASSERT_LT(1.0, stats.perf_improvement());
+ stats.Clear();
+
+ // Below the threshold but have been there a long time, closing in to 1.0.
+ stats.set_ram_anchored(30 * 1024 * 1024);
+ FlushOpPerfImprovementPolicy::SetPerfImprovementForFlush(&stats, 60 * 50 * 1000);
+ ASSERT_LT(0.7, stats.perf_improvement());
+ ASSERT_GT(1.0, stats.perf_improvement());
+ stats.Clear();
+}
+
+} // namespace tablet
+} // namespace kudu
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/tablet_replica.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet_replica.cc b/src/kudu/tablet/tablet_replica.cc
new file mode 100644
index 0000000..3914dc9
--- /dev/null
+++ b/src/kudu/tablet/tablet_replica.cc
@@ -0,0 +1,669 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "kudu/tablet/tablet_replica.h"
+
+#include <algorithm>
+#include <gflags/gflags.h>
+#include <memory>
+#include <mutex>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "kudu/consensus/consensus.h"
+#include "kudu/consensus/consensus_meta.h"
+#include "kudu/consensus/log.h"
+#include "kudu/consensus/log_util.h"
+#include "kudu/consensus/opid_util.h"
+#include "kudu/consensus/log_anchor_registry.h"
+#include "kudu/consensus/quorum_util.h"
+#include "kudu/consensus/raft_consensus.h"
+#include "kudu/gutil/mathlimits.h"
+#include "kudu/gutil/stl_util.h"
+#include "kudu/gutil/strings/substitute.h"
+#include "kudu/gutil/sysinfo.h"
+#include "kudu/rpc/messenger.h"
+#include "kudu/rpc/remote_method.h"
+#include "kudu/rpc/rpc_service.h"
+#include "kudu/rpc/service_pool.h"
+#include "kudu/tablet/transactions/transaction_driver.h"
+#include "kudu/tablet/transactions/alter_schema_transaction.h"
+#include "kudu/tablet/transactions/write_transaction.h"
+#include "kudu/tablet/tablet_bootstrap.h"
+#include "kudu/tablet/tablet_metrics.h"
+#include "kudu/tablet/tablet_replica_mm_ops.h"
+#include "kudu/tablet/tablet.pb.h"
+#include "kudu/util/logging.h"
+#include "kudu/util/metrics.h"
+#include "kudu/util/pb_util.h"
+#include "kudu/util/stopwatch.h"
+#include "kudu/util/threadpool.h"
+#include "kudu/util/trace.h"
+
+using std::map;
+using std::shared_ptr;
+using std::unique_ptr;
+
+namespace kudu {
+namespace tablet {
+
+METRIC_DEFINE_histogram(tablet, op_prepare_queue_length, "Operation Prepare Queue Length",
+ MetricUnit::kTasks,
+ "Number of operations waiting to be prepared within this tablet. "
+ "High queue lengths indicate that the server is unable to process "
+ "operations as fast as they are being written to the WAL.",
+ 10000, 2);
+
+METRIC_DEFINE_histogram(tablet, op_prepare_queue_time, "Operation Prepare Queue Time",
+ MetricUnit::kMicroseconds,
+ "Time that operations spent waiting in the prepare queue before being "
+ "processed. High queue times indicate that the server is unable to "
+ "process operations as fast as they are being written to the WAL.",
+ 10000000, 2);
+
+METRIC_DEFINE_histogram(tablet, op_prepare_run_time, "Operation Prepare Run Time",
+ MetricUnit::kMicroseconds,
+ "Time that operations spent being prepared in the tablet. "
+ "High values may indicate that the server is under-provisioned or "
+ "that operations are experiencing high contention with one another for "
+ "locks.",
+ 10000000, 2);
+
+using consensus::Consensus;
+using consensus::ConsensusBootstrapInfo;
+using consensus::ConsensusMetadata;
+using consensus::ConsensusOptions;
+using consensus::ConsensusRound;
+using consensus::OpId;
+using consensus::RaftConfigPB;
+using consensus::RaftPeerPB;
+using consensus::RaftConsensus;
+using consensus::TimeManager;
+using consensus::ALTER_SCHEMA_OP;
+using consensus::WRITE_OP;
+using log::Log;
+using log::LogAnchorRegistry;
+using rpc::Messenger;
+using rpc::ResultTracker;
+using strings::Substitute;
+using tserver::TabletServerErrorPB;
+
+TabletReplica::TabletReplica(const scoped_refptr<TabletMetadata>& meta,
+ const consensus::RaftPeerPB& local_peer_pb,
+ ThreadPool* apply_pool,
+ Callback<void(const std::string& reason)> mark_dirty_clbk)
+ : meta_(meta),
+ tablet_id_(meta->tablet_id()),
+ local_peer_pb_(local_peer_pb),
+ state_(NOT_STARTED),
+ last_status_("Tablet initializing..."),
+ apply_pool_(apply_pool),
+ log_anchor_registry_(new LogAnchorRegistry()),
+ mark_dirty_clbk_(std::move(mark_dirty_clbk)) {}
+
+TabletReplica::~TabletReplica() {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ // We should either have called Shutdown(), or we should have never called
+ // Init().
+ CHECK(!tablet_)
+ << "TabletReplica not fully shut down. State: "
+ << TabletStatePB_Name(state_);
+}
+
+Status TabletReplica::Init(const shared_ptr<Tablet>& tablet,
+ const scoped_refptr<server::Clock>& clock,
+ const shared_ptr<Messenger>& messenger,
+ const scoped_refptr<ResultTracker>& result_tracker,
+ const scoped_refptr<Log>& log,
+ const scoped_refptr<MetricEntity>& metric_entity) {
+
+ DCHECK(tablet) << "A TabletReplica must be provided with a Tablet";
+ DCHECK(log) << "A TabletReplica must be provided with a Log";
+
+ RETURN_NOT_OK(ThreadPoolBuilder("prepare").set_max_threads(1).Build(&prepare_pool_));
+ prepare_pool_->SetQueueLengthHistogram(
+ METRIC_op_prepare_queue_length.Instantiate(metric_entity));
+ prepare_pool_->SetQueueTimeMicrosHistogram(
+ METRIC_op_prepare_queue_time.Instantiate(metric_entity));
+ prepare_pool_->SetRunTimeMicrosHistogram(
+ METRIC_op_prepare_run_time.Instantiate(metric_entity));
+
+ {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ CHECK_EQ(BOOTSTRAPPING, state_);
+ tablet_ = tablet;
+ clock_ = clock;
+ messenger_ = messenger;
+ log_ = log;
+ result_tracker_ = result_tracker;
+
+ ConsensusOptions options;
+ options.tablet_id = meta_->tablet_id();
+
+ TRACE("Creating consensus instance");
+
+ unique_ptr<ConsensusMetadata> cmeta;
+ RETURN_NOT_OK(ConsensusMetadata::Load(meta_->fs_manager(), tablet_id_,
+ meta_->fs_manager()->uuid(), &cmeta));
+
+ scoped_refptr<TimeManager> time_manager(new TimeManager(
+ clock, tablet_->mvcc_manager()->GetCleanTimestamp()));
+
+ consensus_ = RaftConsensus::Create(options,
+ std::move(cmeta),
+ local_peer_pb_,
+ metric_entity,
+ time_manager,
+ this,
+ messenger_,
+ log_.get(),
+ tablet_->mem_tracker(),
+ mark_dirty_clbk_);
+ }
+
+ if (tablet_->metrics() != nullptr) {
+ TRACE("Starting instrumentation");
+ txn_tracker_.StartInstrumentation(tablet_->GetMetricEntity());
+ }
+ txn_tracker_.StartMemoryTracking(tablet_->mem_tracker());
+
+ TRACE("TabletReplica::Init() finished");
+ VLOG(2) << "T " << tablet_id() << " P " << consensus_->peer_uuid() << ": Peer Initted";
+ return Status::OK();
+}
+
+Status TabletReplica::Start(const ConsensusBootstrapInfo& bootstrap_info) {
+ std::lock_guard<simple_spinlock> l(state_change_lock_);
+ TRACE("Starting consensus");
+
+ VLOG(2) << "T " << tablet_id() << " P " << consensus_->peer_uuid() << ": Peer starting";
+
+ VLOG(2) << "RaftConfig before starting: " << SecureDebugString(consensus_->CommittedConfig());
+
+ RETURN_NOT_OK(consensus_->Start(bootstrap_info));
+ {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ CHECK_EQ(state_, BOOTSTRAPPING);
+ state_ = RUNNING;
+ }
+
+ // Because we changed the tablet state, we need to re-report the tablet to the master.
+ mark_dirty_clbk_.Run("Started TabletReplica");
+
+ return Status::OK();
+}
+
+const consensus::RaftConfigPB TabletReplica::RaftConfig() const {
+ CHECK(consensus_) << "consensus is null";
+ return consensus_->CommittedConfig();
+}
+
+void TabletReplica::Shutdown() {
+
+ LOG(INFO) << "Initiating TabletReplica shutdown for tablet: " << tablet_id_;
+
+ {
+ std::unique_lock<simple_spinlock> lock(lock_);
+ if (state_ == QUIESCING || state_ == SHUTDOWN) {
+ lock.unlock();
+ WaitUntilShutdown();
+ return;
+ }
+ state_ = QUIESCING;
+ }
+
+ std::lock_guard<simple_spinlock> l(state_change_lock_);
+ // Even though Tablet::Shutdown() also unregisters its ops, we have to do it here
+ // to ensure that any currently running operation finishes before we proceed with
+ // the rest of the shutdown sequence. In particular, a maintenance operation could
+ // indirectly end up calling into the log, which we are about to shut down.
+ if (tablet_) tablet_->UnregisterMaintenanceOps();
+ UnregisterMaintenanceOps();
+
+ if (consensus_) consensus_->Shutdown();
+
+ // TODO: KUDU-183: Keep track of the pending tasks and send an "abort" message.
+ LOG_SLOW_EXECUTION(WARNING, 1000,
+ Substitute("TabletReplica: tablet $0: Waiting for Transactions to complete", tablet_id())) {
+ txn_tracker_.WaitForAllToFinish();
+ }
+
+ if (prepare_pool_) {
+ prepare_pool_->Shutdown();
+ }
+
+ if (log_) {
+ WARN_NOT_OK(log_->Close(), "Error closing the Log.");
+ }
+
+ if (VLOG_IS_ON(1)) {
+ VLOG(1) << "TabletReplica: tablet " << tablet_id() << " shut down!";
+ }
+
+ if (tablet_) {
+ tablet_->Shutdown();
+ }
+
+ // Only mark the peer as SHUTDOWN when all other components have shut down.
+ {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ // Release mem tracker resources.
+ consensus_.reset();
+ tablet_.reset();
+ state_ = SHUTDOWN;
+ }
+}
+
+void TabletReplica::WaitUntilShutdown() {
+ while (true) {
+ {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ if (state_ == SHUTDOWN) {
+ return;
+ }
+ }
+ SleepFor(MonoDelta::FromMilliseconds(10));
+ }
+}
+
+Status TabletReplica::CheckRunning() const {
+ {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ if (state_ != RUNNING) {
+ return Status::IllegalState(Substitute("The tablet is not in a running state: $0",
+ TabletStatePB_Name(state_)));
+ }
+ }
+ return Status::OK();
+}
+
+Status TabletReplica::WaitUntilConsensusRunning(const MonoDelta& timeout) {
+ MonoTime start(MonoTime::Now());
+
+ int backoff_exp = 0;
+ const int kMaxBackoffExp = 8;
+ while (true) {
+ bool has_consensus = false;
+ TabletStatePB cached_state;
+ {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ cached_state = state_;
+ if (consensus_) {
+ has_consensus = true; // consensus_ is a set-once object.
+ }
+ }
+ if (cached_state == QUIESCING || cached_state == SHUTDOWN) {
+ return Status::IllegalState(
+ Substitute("The tablet is already shutting down or shutdown. State: $0",
+ TabletStatePB_Name(cached_state)));
+ }
+ if (cached_state == RUNNING && has_consensus && consensus_->IsRunning()) {
+ break;
+ }
+ MonoTime now(MonoTime::Now());
+ MonoDelta elapsed(now - start);
+ if (elapsed > timeout) {
+ return Status::TimedOut(Substitute("Consensus is not running after waiting for $0. State; $1",
+ elapsed.ToString(), TabletStatePB_Name(cached_state)));
+ }
+ SleepFor(MonoDelta::FromMilliseconds(1 << backoff_exp));
+ backoff_exp = std::min(backoff_exp + 1, kMaxBackoffExp);
+ }
+ return Status::OK();
+}
+
+Status TabletReplica::SubmitWrite(unique_ptr<WriteTransactionState> state) {
+ RETURN_NOT_OK(CheckRunning());
+
+ state->SetResultTracker(result_tracker_);
+ gscoped_ptr<WriteTransaction> transaction(new WriteTransaction(std::move(state),
+ consensus::LEADER));
+ scoped_refptr<TransactionDriver> driver;
+ RETURN_NOT_OK(NewLeaderTransactionDriver(transaction.PassAs<Transaction>(),
+ &driver));
+ return driver->ExecuteAsync();
+}
+
+Status TabletReplica::SubmitAlterSchema(unique_ptr<AlterSchemaTransactionState> state) {
+ RETURN_NOT_OK(CheckRunning());
+
+ gscoped_ptr<AlterSchemaTransaction> transaction(
+ new AlterSchemaTransaction(std::move(state), consensus::LEADER));
+ scoped_refptr<TransactionDriver> driver;
+ RETURN_NOT_OK(NewLeaderTransactionDriver(transaction.PassAs<Transaction>(), &driver));
+ return driver->ExecuteAsync();
+}
+
+void TabletReplica::GetTabletStatusPB(TabletStatusPB* status_pb_out) const {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ DCHECK(status_pb_out != nullptr);
+ status_pb_out->set_tablet_id(meta_->tablet_id());
+ status_pb_out->set_table_name(meta_->table_name());
+ status_pb_out->set_last_status(last_status_);
+ meta_->partition().ToPB(status_pb_out->mutable_partition());
+ status_pb_out->set_state(state_);
+ status_pb_out->set_tablet_data_state(meta_->tablet_data_state());
+ if (tablet_) {
+ status_pb_out->set_estimated_on_disk_size(tablet_->EstimateOnDiskSize());
+ }
+}
+
+Status TabletReplica::RunLogGC() {
+ if (!CheckRunning().ok()) {
+ return Status::OK();
+ }
+ int32_t num_gced;
+ log::RetentionIndexes retention = GetRetentionIndexes();
+ Status s = log_->GC(retention, &num_gced);
+ if (!s.ok()) {
+ s = s.CloneAndPrepend("Unexpected error while running Log GC from TabletReplica");
+ LOG(ERROR) << s.ToString();
+ }
+ return Status::OK();
+}
+
+void TabletReplica::StatusMessage(const std::string& status) {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ last_status_ = status;
+}
+
+string TabletReplica::last_status() const {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ return last_status_;
+}
+
+void TabletReplica::SetFailed(const Status& error) {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ CHECK(!error.ok());
+ state_ = FAILED;
+ error_ = error;
+ last_status_ = error.ToString();
+}
+
+string TabletReplica::HumanReadableState() const {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ TabletDataState data_state = meta_->tablet_data_state();
+ // If failed, any number of things could have gone wrong.
+ if (state_ == FAILED) {
+ return Substitute("$0 ($1): $2", TabletStatePB_Name(state_),
+ TabletDataState_Name(data_state),
+ error_.ToString());
+ // If it's copying, or tombstoned, that is the important thing
+ // to show.
+ } else if (data_state != TABLET_DATA_READY) {
+ return TabletDataState_Name(data_state);
+ }
+ // Otherwise, the tablet's data is in a "normal" state, so we just display
+ // the runtime state (BOOTSTRAPPING, RUNNING, etc).
+ return TabletStatePB_Name(state_);
+}
+
+void TabletReplica::GetInFlightTransactions(Transaction::TraceType trace_type,
+ vector<consensus::TransactionStatusPB>* out) const {
+ vector<scoped_refptr<TransactionDriver> > pending_transactions;
+ txn_tracker_.GetPendingTransactions(&pending_transactions);
+ for (const scoped_refptr<TransactionDriver>& driver : pending_transactions) {
+ if (driver->state() != nullptr) {
+ consensus::TransactionStatusPB status_pb;
+ status_pb.mutable_op_id()->CopyFrom(driver->GetOpId());
+ switch (driver->tx_type()) {
+ case Transaction::WRITE_TXN:
+ status_pb.set_tx_type(consensus::WRITE_OP);
+ break;
+ case Transaction::ALTER_SCHEMA_TXN:
+ status_pb.set_tx_type(consensus::ALTER_SCHEMA_OP);
+ break;
+ }
+ status_pb.set_description(driver->ToString());
+ int64_t running_for_micros =
+ (MonoTime::Now() - driver->start_time()).ToMicroseconds();
+ status_pb.set_running_for_micros(running_for_micros);
+ if (trace_type == Transaction::TRACE_TXNS) {
+ status_pb.set_trace_buffer(driver->trace()->DumpToString());
+ }
+ out->push_back(status_pb);
+ }
+ }
+}
+
+log::RetentionIndexes TabletReplica::GetRetentionIndexes() const {
+ // Let consensus set a minimum index that should be anchored.
+ // This ensures that we:
+ // (a) don't GC any operations which are still in flight
+ // (b) don't GC any operations that are needed to catch up lagging peers.
+ log::RetentionIndexes ret = consensus_->GetRetentionIndexes();
+
+ // If we never have written to the log, no need to proceed.
+ if (ret.for_durability == 0) return ret;
+
+ // Next, we interrogate the anchor registry.
+ // Returns OK if minimum known, NotFound if no anchors are registered.
+ {
+ int64_t min_anchor_index;
+ Status s = log_anchor_registry_->GetEarliestRegisteredLogIndex(&min_anchor_index);
+ if (PREDICT_FALSE(!s.ok())) {
+ DCHECK(s.IsNotFound()) << "Unexpected error calling LogAnchorRegistry: " << s.ToString();
+ } else {
+ ret.for_durability = std::min(ret.for_durability, min_anchor_index);
+ }
+ }
+
+ // Next, interrogate the TransactionTracker.
+ vector<scoped_refptr<TransactionDriver> > pending_transactions;
+ txn_tracker_.GetPendingTransactions(&pending_transactions);
+ for (const scoped_refptr<TransactionDriver>& driver : pending_transactions) {
+ OpId tx_op_id = driver->GetOpId();
+ // A transaction which doesn't have an opid hasn't been submitted for replication yet and
+ // thus has no need to anchor the log.
+ if (tx_op_id.IsInitialized()) {
+ ret.for_durability = std::min(ret.for_durability, tx_op_id.index());
+ }
+ }
+
+ return ret;
+}
+
+Status TabletReplica::GetReplaySizeMap(map<int64_t, int64_t>* replay_size_map) const {
+ RETURN_NOT_OK(CheckRunning());
+ log_->GetReplaySizeMap(replay_size_map);
+ return Status::OK();
+}
+
+Status TabletReplica::GetGCableDataSize(int64_t* retention_size) const {
+ RETURN_NOT_OK(CheckRunning());
+ *retention_size = log_->GetGCableDataSize(GetRetentionIndexes());
+ return Status::OK();
+}
+
+Status TabletReplica::StartReplicaTransaction(const scoped_refptr<ConsensusRound>& round) {
+ {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ if (state_ != RUNNING && state_ != BOOTSTRAPPING) {
+ return Status::IllegalState(TabletStatePB_Name(state_));
+ }
+ }
+
+ consensus::ReplicateMsg* replicate_msg = round->replicate_msg();
+ DCHECK(replicate_msg->has_timestamp());
+ gscoped_ptr<Transaction> transaction;
+ switch (replicate_msg->op_type()) {
+ case WRITE_OP:
+ {
+ DCHECK(replicate_msg->has_write_request()) << "WRITE_OP replica"
+ " transaction must receive a WriteRequestPB";
+ unique_ptr<WriteTransactionState> tx_state(
+ new WriteTransactionState(
+ this,
+ &replicate_msg->write_request(),
+ replicate_msg->has_request_id() ? &replicate_msg->request_id() : nullptr));
+ tx_state->SetResultTracker(result_tracker_);
+
+ transaction.reset(new WriteTransaction(std::move(tx_state), consensus::REPLICA));
+ break;
+ }
+ case ALTER_SCHEMA_OP:
+ {
+ DCHECK(replicate_msg->has_alter_schema_request()) << "ALTER_SCHEMA_OP replica"
+ " transaction must receive an AlterSchemaRequestPB";
+ unique_ptr<AlterSchemaTransactionState> tx_state(
+ new AlterSchemaTransactionState(this, &replicate_msg->alter_schema_request(),
+ nullptr));
+ transaction.reset(
+ new AlterSchemaTransaction(std::move(tx_state), consensus::REPLICA));
+ break;
+ }
+ default:
+ LOG(FATAL) << "Unsupported Operation Type";
+ }
+
+ // TODO(todd) Look at wiring the stuff below on the driver
+ TransactionState* state = transaction->state();
+ state->set_consensus_round(round);
+
+ scoped_refptr<TransactionDriver> driver;
+ RETURN_NOT_OK(NewReplicaTransactionDriver(std::move(transaction), &driver));
+
+ // Unretained is required to avoid a refcount cycle.
+ state->consensus_round()->SetConsensusReplicatedCallback(
+ Bind(&TransactionDriver::ReplicationFinished, Unretained(driver.get())));
+
+ RETURN_NOT_OK(driver->ExecuteAsync());
+ return Status::OK();
+}
+
+Status TabletReplica::NewLeaderTransactionDriver(gscoped_ptr<Transaction> transaction,
+ scoped_refptr<TransactionDriver>* driver) {
+ scoped_refptr<TransactionDriver> tx_driver = new TransactionDriver(
+ &txn_tracker_,
+ consensus_.get(),
+ log_.get(),
+ prepare_pool_.get(),
+ apply_pool_,
+ &txn_order_verifier_);
+ RETURN_NOT_OK(tx_driver->Init(std::move(transaction), consensus::LEADER));
+ driver->swap(tx_driver);
+
+ return Status::OK();
+}
+
+Status TabletReplica::NewReplicaTransactionDriver(gscoped_ptr<Transaction> transaction,
+ scoped_refptr<TransactionDriver>* driver) {
+ scoped_refptr<TransactionDriver> tx_driver = new TransactionDriver(
+ &txn_tracker_,
+ consensus_.get(),
+ log_.get(),
+ prepare_pool_.get(),
+ apply_pool_,
+ &txn_order_verifier_);
+ RETURN_NOT_OK(tx_driver->Init(std::move(transaction), consensus::REPLICA));
+ driver->swap(tx_driver);
+
+ return Status::OK();
+}
+
+void TabletReplica::RegisterMaintenanceOps(MaintenanceManager* maint_mgr) {
+ // Taking state_change_lock_ ensures that we don't shut down concurrently with
+ // this last start-up task.
+ std::lock_guard<simple_spinlock> l(state_change_lock_);
+
+ if (state() != RUNNING) {
+ LOG(WARNING) << "Not registering maintenance operations for " << tablet_
+ << ": tablet not in RUNNING state";
+ return;
+ }
+
+ DCHECK(maintenance_ops_.empty());
+
+ gscoped_ptr<MaintenanceOp> mrs_flush_op(new FlushMRSOp(this));
+ maint_mgr->RegisterOp(mrs_flush_op.get());
+ maintenance_ops_.push_back(mrs_flush_op.release());
+
+ gscoped_ptr<MaintenanceOp> dms_flush_op(new FlushDeltaMemStoresOp(this));
+ maint_mgr->RegisterOp(dms_flush_op.get());
+ maintenance_ops_.push_back(dms_flush_op.release());
+
+ gscoped_ptr<MaintenanceOp> log_gc(new LogGCOp(this));
+ maint_mgr->RegisterOp(log_gc.get());
+ maintenance_ops_.push_back(log_gc.release());
+
+ tablet_->RegisterMaintenanceOps(maint_mgr);
+}
+
+void TabletReplica::UnregisterMaintenanceOps() {
+ DCHECK(state_change_lock_.is_locked());
+ for (MaintenanceOp* op : maintenance_ops_) {
+ op->Unregister();
+ }
+ STLDeleteElements(&maintenance_ops_);
+}
+
+Status FlushInflightsToLogCallback::WaitForInflightsAndFlushLog() {
+ // This callback is triggered prior to any TabletMetadata flush.
+ // The guarantee that we are trying to enforce is this:
+ //
+ // If an operation has been flushed to stable storage (eg a DRS or DeltaFile)
+ // then its COMMIT message must be present in the log.
+ //
+ // The purpose for this is so that, during bootstrap, we can accurately identify
+ // whether each operation has been flushed. If we don't see a COMMIT message for
+ // an operation, then we assume it was not completely applied and needs to be
+ // re-applied. Thus, if we had something on disk but with no COMMIT message,
+ // we'd attempt to double-apply the write, resulting in an error (eg trying to
+ // delete an already-deleted row).
+ //
+ // So, to enforce this property, we do two steps:
+ //
+ // 1) Wait for any operations which are already mid-Apply() to Commit() in MVCC.
+ //
+ // Because the operations always enqueue their COMMIT message to the log
+ // before calling Commit(), this ensures that any in-flight operations have
+ // their commit messages "en route".
+ //
+ // NOTE: we only wait for those operations that have started their Apply() phase.
+ // Any operations which haven't yet started applying haven't made any changes
+ // to in-memory state: thus, they obviously couldn't have made any changes to
+ // on-disk storage either (data can only get to the disk by going through an in-memory
+ // store). Only those that have started Apply() could have potentially written some
+ // data which is now on disk.
+ //
+ // Perhaps more importantly, if we waited on operations that hadn't started their
+ // Apply() phase, we might be waiting forever -- for example, if a follower has been
+ // partitioned from its leader, it may have operations sitting around in flight
+ // for quite a long time before eventually aborting or committing. This would
+ // end up blocking all flushes if we waited on it.
+ //
+ // 2) Flush the log
+ //
+ // This ensures that the above-mentioned commit messages are not just enqueued
+ // to the log, but also on disk.
+ VLOG(1) << "T " << tablet_->metadata()->tablet_id()
+ << ": Waiting for in-flight transactions to commit.";
+ LOG_SLOW_EXECUTION(WARNING, 200, "Committing in-flights took a long time.") {
+ tablet_->mvcc_manager()->WaitForApplyingTransactionsToCommit();
+ }
+ VLOG(1) << "T " << tablet_->metadata()->tablet_id()
+ << ": Waiting for the log queue to be flushed.";
+ LOG_SLOW_EXECUTION(WARNING, 200, "Flushing the Log queue took a long time.") {
+ RETURN_NOT_OK(log_->WaitUntilAllFlushed());
+ }
+ return Status::OK();
+}
+
+
+} // namespace tablet
+} // namespace kudu
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/tablet_replica.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet_replica.h b/src/kudu/tablet/tablet_replica.h
new file mode 100644
index 0000000..7f207cb
--- /dev/null
+++ b/src/kudu/tablet/tablet_replica.h
@@ -0,0 +1,377 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#ifndef KUDU_TABLET_TABLET_REPLICA_H_
+#define KUDU_TABLET_TABLET_REPLICA_H_
+
+#include <map>
+#include <memory>
+#include <mutex>
+#include <string>
+#include <vector>
+
+#include "kudu/consensus/consensus.h"
+#include "kudu/consensus/log.h"
+#include "kudu/consensus/time_manager.h"
+#include "kudu/gutil/callback.h"
+#include "kudu/gutil/ref_counted.h"
+#include "kudu/tablet/tablet.h"
+#include "kudu/tablet/transaction_order_verifier.h"
+#include "kudu/tablet/transactions/transaction_tracker.h"
+#include "kudu/util/metrics.h"
+#include "kudu/util/semaphore.h"
+
+namespace kudu {
+
+namespace log {
+class LogAnchorRegistry;
+}
+
+namespace rpc {
+class Messenger;
+class ResultTracker;
+}
+
+namespace tserver {
+class CatchUpServiceTest;
+}
+
+class MaintenanceManager;
+class MaintenanceOp;
+
+namespace tablet {
+class LeaderTransactionDriver;
+class ReplicaTransactionDriver;
+class TabletReplica;
+class TabletStatusPB;
+class TabletStatusListener;
+class TransactionDriver;
+
+// Interface by which various tablet-related processes can report back their status
+// to TabletReplica without having to have a circular class dependency, and so that
+// those other classes can be easily tested without constructing a TabletReplica.
+class TabletStatusListener {
+ public:
+ virtual ~TabletStatusListener() {}
+
+ virtual void StatusMessage(const std::string& status) = 0;
+};
+
+// A replica in a tablet consensus configuration, which coordinates writes to tablets.
+// Each time Write() is called this class appends a new entry to a replicated
+// state machine through a consensus algorithm, which makes sure that other
+// peers see the same updates in the same order. In addition to this, this
+// class also splits the work and coordinates multi-threaded execution.
+class TabletReplica : public RefCountedThreadSafe<TabletReplica>,
+ public consensus::ReplicaTransactionFactory,
+ public TabletStatusListener {
+ public:
+ TabletReplica(const scoped_refptr<TabletMetadata>& meta,
+ const consensus::RaftPeerPB& local_peer_pb, ThreadPool* apply_pool,
+ Callback<void(const std::string& reason)> mark_dirty_clbk);
+
+ // Initializes the TabletReplica, namely creating the Log and initializing
+ // Consensus.
+ Status Init(const std::shared_ptr<tablet::Tablet>& tablet,
+ const scoped_refptr<server::Clock>& clock,
+ const std::shared_ptr<rpc::Messenger>& messenger,
+ const scoped_refptr<rpc::ResultTracker>& result_tracker,
+ const scoped_refptr<log::Log>& log,
+ const scoped_refptr<MetricEntity>& metric_entity);
+
+ // Starts the TabletReplica, making it available for Write()s. If this
+ // TabletReplica is part of a consensus configuration this will connect it to other replicas
+ // in the consensus configuration.
+ Status Start(const consensus::ConsensusBootstrapInfo& info);
+
+ // Shutdown this tablet replica.
+ // If a shutdown is already in progress, blocks until that shutdown is complete.
+ void Shutdown();
+
+ // Check that the tablet is in a RUNNING state.
+ Status CheckRunning() const;
+
+ // Wait until the tablet is in a RUNNING state or if there's a timeout.
+ // TODO have a way to wait for any state?
+ Status WaitUntilConsensusRunning(const MonoDelta& timeout);
+
+ // Submits a write to a tablet and executes it asynchronously.
+ // The caller is expected to build and pass a TrasactionContext that points
+ // to the RPC WriteRequest, WriteResponse, RpcContext and to the tablet's
+ // MvccManager.
+ Status SubmitWrite(std::unique_ptr<WriteTransactionState> tx_state);
+
+ // Called by the tablet service to start an alter schema transaction.
+ //
+ // The transaction contains all the information required to execute the
+ // AlterSchema operation and send the response back.
+ //
+ // If the returned Status is OK, the response to the client will be sent
+ // asynchronously. Otherwise the tablet service will have to send the response directly.
+ //
+ // The AlterSchema operation is taking the tablet component lock in exclusive mode
+ // meaning that no other operation on the tablet can be executed while the
+ // AlterSchema is in progress.
+ Status SubmitAlterSchema(std::unique_ptr<AlterSchemaTransactionState> tx_state);
+
+ void GetTabletStatusPB(TabletStatusPB* status_pb_out) const;
+
+ // Used by consensus to create and start a new ReplicaTransaction.
+ virtual Status StartReplicaTransaction(
+ const scoped_refptr<consensus::ConsensusRound>& round) OVERRIDE;
+
+ consensus::Consensus* consensus() {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ return consensus_.get();
+ }
+
+ scoped_refptr<consensus::Consensus> shared_consensus() const {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ return consensus_;
+ }
+
+ Tablet* tablet() const {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ return tablet_.get();
+ }
+
+ scoped_refptr<consensus::TimeManager> time_manager() const {
+ return consensus_->time_manager();
+ }
+
+ std::shared_ptr<Tablet> shared_tablet() const {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ return tablet_;
+ }
+
+ const TabletStatePB state() const {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ return state_;
+ }
+
+ // Returns the current Raft configuration.
+ const consensus::RaftConfigPB RaftConfig() const;
+
+ // If any peers in the consensus configuration lack permanent uuids, get them via an
+ // RPC call and update.
+ // TODO: move this to raft_consensus.h.
+ Status UpdatePermanentUuids();
+
+ // Sets the tablet to a BOOTSTRAPPING state, indicating it is starting up.
+ void SetBootstrapping() {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ CHECK_EQ(NOT_STARTED, state_);
+ state_ = BOOTSTRAPPING;
+ }
+
+ // Implementation of TabletStatusListener::StatusMessage().
+ void StatusMessage(const std::string& status) override;
+
+ // Retrieve the last human-readable status of this tablet replica.
+ std::string last_status() const;
+
+ // Sets the tablet state to FAILED additionally setting the error to the provided
+ // one.
+ void SetFailed(const Status& error);
+
+ // Returns the error that occurred, when state is FAILED.
+ Status error() const {
+ std::lock_guard<simple_spinlock> lock(lock_);
+ return error_;
+ }
+
+ // Returns a human-readable string indicating the state of the tablet.
+ // Typically this looks like "NOT_STARTED", "TABLET_DATA_COPYING",
+ // etc. For use in places like the Web UI.
+ std::string HumanReadableState() const;
+
+ // Adds list of transactions in-flight at the time of the call to 'out'.
+ void GetInFlightTransactions(Transaction::TraceType trace_type,
+ std::vector<consensus::TransactionStatusPB>* out) const;
+
+ // Returns the log indexes to be retained for durability and to catch up peers.
+ // Used for selection of log segments to delete during Log GC.
+ log::RetentionIndexes GetRetentionIndexes() const;
+
+ // See Log::GetReplaySizeMap(...).
+ //
+ // Returns a non-ok status if the tablet isn't running.
+ Status GetReplaySizeMap(std::map<int64_t, int64_t>* replay_size_map) const;
+
+ // Returns the amount of bytes that would be GC'd if RunLogGC() was called.
+ //
+ // Returns a non-ok status if the tablet isn't running.
+ Status GetGCableDataSize(int64_t* retention_size) const;
+
+ // Return a pointer to the Log.
+ // TabletReplica keeps a reference to Log after Init().
+ log::Log* log() const {
+ return log_.get();
+ }
+
+ server::Clock* clock() {
+ return clock_.get();
+ }
+
+ const scoped_refptr<log::LogAnchorRegistry>& log_anchor_registry() const {
+ return log_anchor_registry_;
+ }
+
+ // Returns the tablet_id of the tablet managed by this TabletReplica.
+ // Returns the correct tablet_id even if the underlying tablet is not available
+ // yet.
+ const std::string& tablet_id() const { return tablet_id_; }
+
+ // Convenience method to return the permanent_uuid of this peer.
+ std::string permanent_uuid() const { return tablet_->metadata()->fs_manager()->uuid(); }
+
+ Status NewLeaderTransactionDriver(gscoped_ptr<Transaction> transaction,
+ scoped_refptr<TransactionDriver>* driver);
+
+ Status NewReplicaTransactionDriver(gscoped_ptr<Transaction> transaction,
+ scoped_refptr<TransactionDriver>* driver);
+
+ // Tells the tablet's log to garbage collect.
+ Status RunLogGC();
+
+ // Register the maintenance ops associated with this peer's tablet, also invokes
+ // Tablet::RegisterMaintenanceOps().
+ void RegisterMaintenanceOps(MaintenanceManager* maintenance_manager);
+
+ // Unregister the maintenance ops associated with this peer's tablet.
+ // This method is not thread safe.
+ void UnregisterMaintenanceOps();
+
+ // Return pointer to the transaction tracker for this peer.
+ const TransactionTracker* transaction_tracker() const { return &txn_tracker_; }
+
+ const scoped_refptr<TabletMetadata>& tablet_metadata() const {
+ return meta_;
+ }
+
+ // Marks the tablet as dirty so that it's included in the next heartbeat.
+ void MarkTabletDirty(const std::string& reason) {
+ mark_dirty_clbk_.Run(reason);
+ }
+
+ private:
+ friend class RefCountedThreadSafe<TabletReplica>;
+ friend class TabletReplicaTest;
+ FRIEND_TEST(TabletReplicaTest, TestMRSAnchorPreventsLogGC);
+ FRIEND_TEST(TabletReplicaTest, TestDMSAnchorPreventsLogGC);
+ FRIEND_TEST(TabletReplicaTest, TestActiveTransactionPreventsLogGC);
+
+ ~TabletReplica();
+
+ // Wait until the TabletReplica is fully in SHUTDOWN state.
+ void WaitUntilShutdown();
+
+ // After bootstrap is complete and consensus is setup this initiates the transactions
+ // that were not complete on bootstrap.
+ // Not implemented yet. See .cc file.
+ Status StartPendingTransactions(consensus::RaftPeerPB::Role my_role,
+ const consensus::ConsensusBootstrapInfo& bootstrap_info);
+
+ const scoped_refptr<TabletMetadata> meta_;
+
+ const std::string tablet_id_;
+
+ const consensus::RaftPeerPB local_peer_pb_;
+
+ TabletStatePB state_;
+ Status error_;
+ TransactionTracker txn_tracker_;
+ TransactionOrderVerifier txn_order_verifier_;
+ scoped_refptr<log::Log> log_;
+ std::shared_ptr<Tablet> tablet_;
+ std::shared_ptr<rpc::Messenger> messenger_;
+ scoped_refptr<consensus::Consensus> consensus_;
+ simple_spinlock prepare_replicate_lock_;
+
+ // Lock protecting state_, last_status_, as well as smart pointers to collaborating
+ // classes such as tablet_ and consensus_.
+ mutable simple_spinlock lock_;
+
+ // The human-readable last status of the tablet, displayed on the web page, command line
+ // tools, etc.
+ std::string last_status_;
+
+ // Lock taken during Init/Shutdown which ensures that only a single thread
+ // attempts to perform major lifecycle operations (Init/Shutdown) at once.
+ // This must be acquired before acquiring lock_ if they are acquired together.
+ // We don't just use lock_ since the lifecycle operations may take a while
+ // and we'd like other threads to be able to quickly poll the state_ variable
+ // during them in order to reject RPCs, etc.
+ mutable simple_spinlock state_change_lock_;
+
+ // IMPORTANT: correct execution of PrepareTask assumes that 'prepare_pool_'
+ // is single-threaded, moving to a multi-tablet setup where multiple TabletReplicas
+ // use the same 'prepare_pool_' needs to enforce that, for a single
+ // TabletReplica, PrepareTasks are executed *serially*.
+ // TODO move the prepare pool to TabletServer.
+ gscoped_ptr<ThreadPool> prepare_pool_;
+
+ // Pool that executes apply tasks for transactions. This is a multi-threaded
+ // pool, constructor-injected by either the Master (for system tables) or
+ // the Tablet server.
+ ThreadPool* apply_pool_;
+
+ scoped_refptr<server::Clock> clock_;
+
+ scoped_refptr<log::LogAnchorRegistry> log_anchor_registry_;
+
+ // Function to mark this TabletReplica's tablet as dirty in the TSTabletManager.
+ //
+ // Must be called whenever cluster membership or leadership changes, or when
+ // the tablet's schema changes.
+ Callback<void(const std::string& reason)> mark_dirty_clbk_;
+
+ // List of maintenance operations for the tablet that need information that only the peer
+ // can provide.
+ std::vector<MaintenanceOp*> maintenance_ops_;
+
+ // The result tracker for writes.
+ scoped_refptr<rpc::ResultTracker> result_tracker_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabletReplica);
+};
+
+// A callback to wait for the in-flight transactions to complete and to flush
+// the Log when they do.
+// Tablet is passed as a raw pointer as this callback is set in TabletMetadata and
+// were we to keep the tablet as a shared_ptr a circular dependency would occur:
+// callback->tablet->metadata->callback. Since the tablet indirectly owns this
+// callback we know that is must still be alive when it fires.
+class FlushInflightsToLogCallback : public RefCountedThreadSafe<FlushInflightsToLogCallback> {
+ public:
+ FlushInflightsToLogCallback(Tablet* tablet,
+ const scoped_refptr<log::Log>& log)
+ : tablet_(tablet),
+ log_(log) {}
+
+ Status WaitForInflightsAndFlushLog();
+
+ private:
+ Tablet* tablet_;
+ scoped_refptr<log::Log> log_;
+};
+
+
+} // namespace tablet
+} // namespace kudu
+
+#endif /* KUDU_TABLET_TABLET_REPLICA_H_ */
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/tablet_replica_mm_ops.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet_replica_mm_ops.cc b/src/kudu/tablet/tablet_replica_mm_ops.cc
new file mode 100644
index 0000000..85650ff
--- /dev/null
+++ b/src/kudu/tablet/tablet_replica_mm_ops.cc
@@ -0,0 +1,246 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "kudu/tablet/tablet_replica_mm_ops.h"
+
+#include <algorithm>
+#include <gflags/gflags.h>
+#include <map>
+#include <mutex>
+#include <string>
+
+#include "kudu/gutil/strings/substitute.h"
+#include "kudu/tablet/tablet_metrics.h"
+#include "kudu/util/flag_tags.h"
+#include "kudu/util/maintenance_manager.h"
+#include "kudu/util/metrics.h"
+
+DEFINE_int32(flush_threshold_mb, 1024,
+ "Size at which MemRowSet flushes are triggered. "
+ "A MRS can still flush below this threshold if it if hasn't flushed in a while, "
+ "or if the server-wide memory limit has been reached.");
+TAG_FLAG(flush_threshold_mb, experimental);
+
+DEFINE_int32(flush_threshold_secs, 2 * 60,
+ "Number of seconds after which a non-empty MemRowSet will become flushable "
+ "even if it is not large.");
+TAG_FLAG(flush_threshold_secs, experimental);
+
+
+METRIC_DEFINE_gauge_uint32(tablet, log_gc_running,
+ "Log GCs Running",
+ kudu::MetricUnit::kOperations,
+ "Number of log GC operations currently running.");
+METRIC_DEFINE_histogram(tablet, log_gc_duration,
+ "Log GC Duration",
+ kudu::MetricUnit::kMilliseconds,
+ "Time spent garbage collecting the logs.", 60000LU, 1);
+
+namespace kudu {
+namespace tablet {
+
+using std::map;
+using strings::Substitute;
+
+// Upper bound for how long it takes to reach "full perf improvement" in time-based flushing.
+const double kFlushUpperBoundMs = 60 * 60 * 1000;
+
+//
+// FlushOpPerfImprovementPolicy.
+//
+
+void FlushOpPerfImprovementPolicy::SetPerfImprovementForFlush(MaintenanceOpStats* stats,
+ double elapsed_ms) {
+ if (stats->ram_anchored() > FLAGS_flush_threshold_mb * 1024 * 1024) {
+ // If we're over the user-specified flush threshold, then consider the perf
+ // improvement to be 1 for every extra MB. This produces perf_improvement results
+ // which are much higher than any compaction would produce, and means that, when
+ // there is an MRS over threshold, a flush will almost always be selected instead of
+ // a compaction. That's not necessarily a good thing, but in the absence of better
+ // heuristics, it will do for now.
+ double extra_mb =
+ static_cast<double>(FLAGS_flush_threshold_mb - (stats->ram_anchored()) / (1024 * 1024));
+ stats->set_perf_improvement(extra_mb);
+ } else if (elapsed_ms > FLAGS_flush_threshold_secs * 1000) {
+ // Even if we aren't over the threshold, consider flushing if we haven't flushed
+ // in a long time. But, don't give it a large perf_improvement score. We should
+ // only do this if we really don't have much else to do, and if we've already waited a bit.
+ // The following will give an improvement that's between 0.0 and 1.0, gradually growing
+ // as 'elapsed_ms' approaches 'kFlushUpperBoundMs'.
+ double perf = elapsed_ms / kFlushUpperBoundMs;
+ if (perf > 1.0) {
+ perf = 1.0;
+ }
+ stats->set_perf_improvement(perf);
+ }
+}
+
+//
+// FlushMRSOp.
+//
+
+void FlushMRSOp::UpdateStats(MaintenanceOpStats* stats) {
+ std::lock_guard<simple_spinlock> l(lock_);
+
+ map<int64_t, int64_t> replay_size_map;
+ if (tablet_replica_->tablet()->MemRowSetEmpty() ||
+ !tablet_replica_->GetReplaySizeMap(&replay_size_map).ok()) {
+ return;
+ }
+
+ {
+ std::unique_lock<Semaphore> lock(tablet_replica_->tablet()->rowsets_flush_sem_,
+ std::defer_lock);
+ stats->set_runnable(lock.try_lock());
+ }
+
+ stats->set_ram_anchored(tablet_replica_->tablet()->MemRowSetSize());
+ stats->set_logs_retained_bytes(
+ tablet_replica_->tablet()->MemRowSetLogReplaySize(replay_size_map));
+
+ // TODO(todd): use workload statistics here to find out how "hot" the tablet has
+ // been in the last 5 minutes.
+ FlushOpPerfImprovementPolicy::SetPerfImprovementForFlush(
+ stats,
+ time_since_flush_.elapsed().wall_millis());
+}
+
+bool FlushMRSOp::Prepare() {
+ // Try to acquire the rowsets_flush_sem_. If we can't, the Prepare step
+ // fails. This also implies that only one instance of FlushMRSOp can be
+ // running at once.
+ return tablet_replica_->tablet()->rowsets_flush_sem_.try_lock();
+}
+
+void FlushMRSOp::Perform() {
+ CHECK(!tablet_replica_->tablet()->rowsets_flush_sem_.try_lock());
+
+ KUDU_CHECK_OK_PREPEND(tablet_replica_->tablet()->FlushUnlocked(),
+ Substitute("FlushMRS failed on $0", tablet_replica_->tablet_id()));
+
+ {
+ std::lock_guard<simple_spinlock> l(lock_);
+ time_since_flush_.start();
+ }
+ tablet_replica_->tablet()->rowsets_flush_sem_.unlock();
+}
+
+scoped_refptr<Histogram> FlushMRSOp::DurationHistogram() const {
+ return tablet_replica_->tablet()->metrics()->flush_mrs_duration;
+}
+
+scoped_refptr<AtomicGauge<uint32_t> > FlushMRSOp::RunningGauge() const {
+ return tablet_replica_->tablet()->metrics()->flush_mrs_running;
+}
+
+//
+// FlushDeltaMemStoresOp.
+//
+
+void FlushDeltaMemStoresOp::UpdateStats(MaintenanceOpStats* stats) {
+ std::lock_guard<simple_spinlock> l(lock_);
+ int64_t dms_size;
+ int64_t retention_size;
+ map<int64_t, int64_t> max_idx_to_replay_size;
+ if (tablet_replica_->tablet()->DeltaMemRowSetEmpty() ||
+ !tablet_replica_->GetReplaySizeMap(&max_idx_to_replay_size).ok()) {
+ return;
+ }
+ tablet_replica_->tablet()->GetInfoForBestDMSToFlush(max_idx_to_replay_size,
+ &dms_size, &retention_size);
+
+ stats->set_ram_anchored(dms_size);
+ stats->set_runnable(true);
+ stats->set_logs_retained_bytes(retention_size);
+
+ FlushOpPerfImprovementPolicy::SetPerfImprovementForFlush(
+ stats,
+ time_since_flush_.elapsed().wall_millis());
+}
+
+void FlushDeltaMemStoresOp::Perform() {
+ map<int64_t, int64_t> max_idx_to_replay_size;
+ if (!tablet_replica_->GetReplaySizeMap(&max_idx_to_replay_size).ok()) {
+ LOG(WARNING) << "Won't flush deltas since tablet shutting down: "
+ << tablet_replica_->tablet_id();
+ return;
+ }
+ KUDU_CHECK_OK_PREPEND(tablet_replica_->tablet()->FlushDMSWithHighestRetention(
+ max_idx_to_replay_size),
+ Substitute("Failed to flush DMS on $0",
+ tablet_replica_->tablet()->tablet_id()));
+ {
+ std::lock_guard<simple_spinlock> l(lock_);
+ time_since_flush_.start();
+ }
+}
+
+scoped_refptr<Histogram> FlushDeltaMemStoresOp::DurationHistogram() const {
+ return tablet_replica_->tablet()->metrics()->flush_dms_duration;
+}
+
+scoped_refptr<AtomicGauge<uint32_t> > FlushDeltaMemStoresOp::RunningGauge() const {
+ return tablet_replica_->tablet()->metrics()->flush_dms_running;
+}
+
+//
+// LogGCOp.
+//
+
+LogGCOp::LogGCOp(TabletReplica* tablet_replica)
+ : MaintenanceOp(StringPrintf("LogGCOp(%s)", tablet_replica->tablet()->tablet_id().c_str()),
+ MaintenanceOp::LOW_IO_USAGE),
+ tablet_replica_(tablet_replica),
+ log_gc_duration_(METRIC_log_gc_duration.Instantiate(
+ tablet_replica->tablet()->GetMetricEntity())),
+ log_gc_running_(METRIC_log_gc_running.Instantiate(
+ tablet_replica->tablet()->GetMetricEntity(), 0)),
+ sem_(1) {}
+
+void LogGCOp::UpdateStats(MaintenanceOpStats* stats) {
+ int64_t retention_size;
+
+ if (!tablet_replica_->GetGCableDataSize(&retention_size).ok()) {
+ return;
+ }
+
+ stats->set_logs_retained_bytes(retention_size);
+ stats->set_runnable(sem_.GetValue() == 1);
+}
+
+bool LogGCOp::Prepare() {
+ return sem_.try_lock();
+}
+
+void LogGCOp::Perform() {
+ CHECK(!sem_.try_lock());
+
+ tablet_replica_->RunLogGC();
+
+ sem_.unlock();
+}
+
+scoped_refptr<Histogram> LogGCOp::DurationHistogram() const {
+ return log_gc_duration_;
+}
+
+scoped_refptr<AtomicGauge<uint32_t> > LogGCOp::RunningGauge() const {
+ return log_gc_running_;
+}
+
+} // namespace tablet
+} // namespace kudu
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/tablet_replica_mm_ops.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet_replica_mm_ops.h b/src/kudu/tablet/tablet_replica_mm_ops.h
new file mode 100644
index 0000000..fc391ed
--- /dev/null
+++ b/src/kudu/tablet/tablet_replica_mm_ops.h
@@ -0,0 +1,133 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#ifndef KUDU_TABLET_TABLET_REPLICA_MM_OPS_H_
+#define KUDU_TABLET_TABLET_REPLICA_MM_OPS_H_
+
+#include "kudu/tablet/tablet_replica.h"
+#include "kudu/util/maintenance_manager.h"
+#include "kudu/util/stopwatch.h"
+
+namespace kudu {
+
+class Histogram;
+template<class T>
+class AtomicGauge;
+
+namespace tablet {
+
+class FlushOpPerfImprovementPolicy {
+ public:
+ ~FlushOpPerfImprovementPolicy() {}
+
+ // Sets the performance improvement based on the anchored ram if it's over the threshold,
+ // else it will set it based on how long it has been since the last flush.
+ static void SetPerfImprovementForFlush(MaintenanceOpStats* stats, double elapsed_ms);
+
+ private:
+ FlushOpPerfImprovementPolicy() {}
+};
+
+// Maintenance op for MRS flush. Only one can happen at a time.
+class FlushMRSOp : public MaintenanceOp {
+ public:
+ explicit FlushMRSOp(TabletReplica* tablet_replica)
+ : MaintenanceOp(StringPrintf("FlushMRSOp(%s)", tablet_replica->tablet()->tablet_id().c_str()),
+ MaintenanceOp::HIGH_IO_USAGE),
+ tablet_replica_(tablet_replica) {
+ time_since_flush_.start();
+ }
+
+ virtual void UpdateStats(MaintenanceOpStats* stats) OVERRIDE;
+
+ virtual bool Prepare() OVERRIDE;
+
+ virtual void Perform() OVERRIDE;
+
+ virtual scoped_refptr<Histogram> DurationHistogram() const OVERRIDE;
+
+ virtual scoped_refptr<AtomicGauge<uint32_t> > RunningGauge() const OVERRIDE;
+
+ private:
+ // Lock protecting time_since_flush_.
+ mutable simple_spinlock lock_;
+ Stopwatch time_since_flush_;
+
+ TabletReplica *const tablet_replica_;
+};
+
+// Maintenance op for DMS flush.
+// Reports stats for all the DMS this tablet contains but only flushes one in Perform().
+class FlushDeltaMemStoresOp : public MaintenanceOp {
+ public:
+ explicit FlushDeltaMemStoresOp(TabletReplica* tablet_replica)
+ : MaintenanceOp(StringPrintf("FlushDeltaMemStoresOp(%s)",
+ tablet_replica->tablet()->tablet_id().c_str()),
+ MaintenanceOp::HIGH_IO_USAGE),
+ tablet_replica_(tablet_replica) {
+ time_since_flush_.start();
+ }
+
+ virtual void UpdateStats(MaintenanceOpStats* stats) OVERRIDE;
+
+ virtual bool Prepare() OVERRIDE {
+ return true;
+ }
+
+ virtual void Perform() OVERRIDE;
+
+ virtual scoped_refptr<Histogram> DurationHistogram() const OVERRIDE;
+
+ virtual scoped_refptr<AtomicGauge<uint32_t> > RunningGauge() const OVERRIDE;
+
+ private:
+ // Lock protecting time_since_flush_
+ mutable simple_spinlock lock_;
+ Stopwatch time_since_flush_;
+
+ TabletReplica *const tablet_replica_;
+};
+
+// Maintenance task that runs log GC. Reports log retention that represents the amount of data
+// that can be GC'd.
+//
+// Only one LogGC op can run at a time.
+class LogGCOp : public MaintenanceOp {
+ public:
+ explicit LogGCOp(TabletReplica* tablet_replica);
+
+ virtual void UpdateStats(MaintenanceOpStats* stats) OVERRIDE;
+
+ virtual bool Prepare() OVERRIDE;
+
+ virtual void Perform() OVERRIDE;
+
+ virtual scoped_refptr<Histogram> DurationHistogram() const OVERRIDE;
+
+ virtual scoped_refptr<AtomicGauge<uint32_t> > RunningGauge() const OVERRIDE;
+
+ private:
+ TabletReplica *const tablet_replica_;
+ scoped_refptr<Histogram> log_gc_duration_;
+ scoped_refptr<AtomicGauge<uint32_t> > log_gc_running_;
+ mutable Semaphore sem_;
+};
+
+} // namespace tablet
+} // namespace kudu
+
+#endif /* KUDU_TABLET_TABLET_REPLICA_MM_OPS_H_ */
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/transactions/alter_schema_transaction.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/transactions/alter_schema_transaction.cc b/src/kudu/tablet/transactions/alter_schema_transaction.cc
index 92a626d..38d2c56 100644
--- a/src/kudu/tablet/transactions/alter_schema_transaction.cc
+++ b/src/kudu/tablet/transactions/alter_schema_transaction.cc
@@ -23,7 +23,7 @@
#include "kudu/rpc/rpc_context.h"
#include "kudu/server/hybrid_clock.h"
#include "kudu/tablet/tablet.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tablet/tablet_metrics.h"
#include "kudu/tserver/tserver.pb.h"
#include "kudu/util/pb_util.h"
@@ -86,7 +86,7 @@ Status AlterSchemaTransaction::Prepare() {
return s;
}
- Tablet* tablet = state_->tablet_peer()->tablet();
+ Tablet* tablet = state_->tablet_replica()->tablet();
RETURN_NOT_OK(tablet->CreatePreparedAlterSchema(state(), schema.get()));
state_->AddToAutoReleasePool(schema.release());
@@ -106,15 +106,15 @@ Status AlterSchemaTransaction::Start() {
Status AlterSchemaTransaction::Apply(gscoped_ptr<CommitMsg>* commit_msg) {
TRACE("APPLY ALTER-SCHEMA: Starting");
- Tablet* tablet = state_->tablet_peer()->tablet();
+ Tablet* tablet = state_->tablet_replica()->tablet();
RETURN_NOT_OK(tablet->AlterSchema(state()));
- state_->tablet_peer()->log()
+ state_->tablet_replica()->log()
->SetSchemaForNextLogSegment(*DCHECK_NOTNULL(state_->schema()),
state_->schema_version());
// Altered tablets should be included in the next tserver heartbeat so that
// clients waiting on IsAlterTableDone() are unblocked promptly.
- state_->tablet_peer()->MarkTabletDirty("Alter schema finished");
+ state_->tablet_replica()->MarkTabletDirty("Alter schema finished");
commit_msg->reset(new CommitMsg());
(*commit_msg)->set_op_type(ALTER_SCHEMA_OP);
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/transactions/alter_schema_transaction.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/transactions/alter_schema_transaction.h b/src/kudu/tablet/transactions/alter_schema_transaction.h
index cfcae3f..e1e0ab9 100644
--- a/src/kudu/tablet/transactions/alter_schema_transaction.h
+++ b/src/kudu/tablet/transactions/alter_schema_transaction.h
@@ -42,10 +42,10 @@ class AlterSchemaTransactionState : public TransactionState {
~AlterSchemaTransactionState() {
}
- AlterSchemaTransactionState(TabletPeer* tablet_peer,
+ AlterSchemaTransactionState(TabletReplica* tablet_replica,
const tserver::AlterSchemaRequestPB* request,
tserver::AlterSchemaResponsePB* response)
- : TransactionState(tablet_peer),
+ : TransactionState(tablet_replica),
schema_(NULL),
request_(request),
response_(response) {
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/transactions/transaction.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/transactions/transaction.cc b/src/kudu/tablet/transactions/transaction.cc
index b8681a1..efa6688 100644
--- a/src/kudu/tablet/transactions/transaction.cc
+++ b/src/kudu/tablet/transactions/transaction.cc
@@ -28,8 +28,8 @@ Transaction::Transaction(TransactionState* state, DriverType type, TransactionTy
tx_type_(tx_type) {
}
-TransactionState::TransactionState(TabletPeer* tablet_peer)
- : tablet_peer_(tablet_peer),
+TransactionState::TransactionState(TabletReplica* tablet_replica)
+ : tablet_replica_(tablet_replica),
completion_clbk_(new TransactionCompletionCallback()),
timestamp_error_(0),
arena_(1024, 4 * 1024 * 1024),
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/transactions/transaction.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/transactions/transaction.h b/src/kudu/tablet/transactions/transaction.h
index 4d8b4d5..f0696a6 100644
--- a/src/kudu/tablet/transactions/transaction.h
+++ b/src/kudu/tablet/transactions/transaction.h
@@ -37,7 +37,7 @@ class ResultTracker;
} // namespace rpc
namespace tablet {
-class TabletPeer;
+class TabletReplica;
class TransactionCompletionCallback;
class TransactionState;
@@ -169,8 +169,8 @@ class TransactionState {
return consensus_round_.get();
}
- TabletPeer* tablet_peer() const {
- return tablet_peer_;
+ TabletReplica* tablet_replica() const {
+ return tablet_replica_;
}
// Return metrics related to this transaction.
@@ -257,13 +257,13 @@ class TransactionState {
}
protected:
- explicit TransactionState(TabletPeer* tablet_peer);
+ explicit TransactionState(TabletReplica* tablet_replica);
virtual ~TransactionState();
TransactionMetrics tx_metrics_;
- // The tablet peer that is coordinating this transaction.
- TabletPeer* const tablet_peer_;
+ // The TabletReplica that is coordinating this transaction.
+ TabletReplica* const tablet_replica_;
// The result tracker that will cache the result of this transaction.
scoped_refptr<rpc::ResultTracker> result_tracker_;
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/transactions/transaction_driver.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/transactions/transaction_driver.cc b/src/kudu/tablet/transactions/transaction_driver.cc
index 3050f34..cb6bf64 100644
--- a/src/kudu/tablet/transactions/transaction_driver.cc
+++ b/src/kudu/tablet/transactions/transaction_driver.cc
@@ -23,7 +23,7 @@
#include "kudu/consensus/time_manager.h"
#include "kudu/gutil/strings/strcat.h"
#include "kudu/rpc/result_tracker.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tablet/transactions/transaction_tracker.h"
#include "kudu/util/debug-util.h"
#include "kudu/util/debug/trace_event.h"
@@ -442,7 +442,7 @@ Status TransactionDriver::ApplyAsync() {
order_verifier_->CheckApply(op_id_copy_.index(), prepare_physical_timestamp_);
// Now that the transaction is committed in consensus advance the safe time.
if (transaction_->state()->external_consistency_mode() != COMMIT_WAIT) {
- transaction_->state()->tablet_peer()->tablet()->mvcc_manager()->
+ transaction_->state()->tablet_replica()->tablet()->mvcc_manager()->
AdjustSafeTime(transaction_->state()->timestamp());
}
} else {
@@ -515,7 +515,7 @@ void TransactionDriver::SetResponseTimestamp(TransactionState* transaction_state
Status TransactionDriver::CommitWait() {
MonoTime before = MonoTime::Now();
DCHECK(mutable_state()->external_consistency_mode() == COMMIT_WAIT);
- RETURN_NOT_OK(mutable_state()->tablet_peer()->clock()->WaitUntilAfter(
+ RETURN_NOT_OK(mutable_state()->tablet_replica()->clock()->WaitUntilAfter(
mutable_state()->timestamp(), MonoTime::Max()));
mutable_state()->mutable_metrics()->commit_wait_duration_usec =
(MonoTime::Now() - before).ToMicroseconds();
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/transactions/transaction_tracker.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/transactions/transaction_tracker.cc b/src/kudu/tablet/transactions/transaction_tracker.cc
index 3661747..3ac55a9 100644
--- a/src/kudu/tablet/transactions/transaction_tracker.cc
+++ b/src/kudu/tablet/transactions/transaction_tracker.cc
@@ -23,7 +23,7 @@
#include "kudu/gutil/map-util.h"
#include "kudu/gutil/strings/substitute.h"
-#include "kudu/tablet/tablet_peer.h"
+#include "kudu/tablet/tablet_replica.h"
#include "kudu/tablet/transactions/transaction_driver.h"
#include "kudu/util/flag_tags.h"
#include "kudu/util/logging.h"
@@ -97,12 +97,12 @@ Status TransactionTracker::Add(TransactionDriver* driver) {
}
// May be null in unit tests.
- TabletPeer* peer = driver->state()->tablet_peer();
+ TabletReplica* replica = driver->state()->tablet_replica();
string msg = Substitute(
"Transaction failed, tablet $0 transaction memory consumption ($1) "
"has exceeded its limit ($2) or the limit of an ancestral tracker",
- peer ? peer->tablet()->tablet_id() : "(unknown)",
+ replica ? replica->tablet()->tablet_id() : "(unknown)",
mem_tracker_->consumption(), mem_tracker_->limit());
KLOG_EVERY_N_SECS(WARNING, 1) << msg << THROTTLE_MSG;
http://git-wip-us.apache.org/repos/asf/kudu/blob/7f72105b/src/kudu/tablet/transactions/transaction_tracker.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/transactions/transaction_tracker.h b/src/kudu/tablet/transactions/transaction_tracker.h
index 88a9103..3a3725b 100644
--- a/src/kudu/tablet/transactions/transaction_tracker.h
+++ b/src/kudu/tablet/transactions/transaction_tracker.h
@@ -39,7 +39,7 @@ class MetricEntity;
namespace tablet {
class TransactionDriver;
-// Each TabletPeer has a TransactionTracker which keeps track of pending transactions.
+// Each TabletReplica has a TransactionTracker which keeps track of pending transactions.
// Each "LeaderTransaction" will register itself by calling Add().
// It will remove itself by calling Release().
class TransactionTracker {