Skip to content

Commit

Permalink
KUDU-2750: Add create and alter timestamp to tables
Browse files Browse the repository at this point in the history
Add create and last alteration time to every table. The
timestamps are persisted with 'SysTablesEntryPB' and
displayed on the 'master:port/tables' page.

Change-Id: Ife05719cea26b15fdf2b5667b60c3e89947cdda8
Reviewed-on: http://gerrit.cloudera.org:8080/12842
Reviewed-by: Todd Lipcon <[email protected]>
Tested-by: Kudu Jenkins
  • Loading branch information
helifu authored and toddlipcon committed Mar 26, 2019
1 parent bc63454 commit 4127186
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/kudu/master/catalog_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include <ostream>
#include <set>
#include <string>
#include <time.h>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
Expand Down Expand Up @@ -1737,6 +1738,7 @@ scoped_refptr<TableInfo> CatalogManager::CreateTableInfo(const CreateTableReques
// whereas the user request PB does not.
CHECK_OK(SchemaToPB(schema, metadata->mutable_schema()));
partition_schema.ToPB(metadata->mutable_partition_schema());
metadata->set_create_timestamp(time(nullptr));
return table;
}

Expand Down Expand Up @@ -2435,6 +2437,7 @@ Status CatalogManager::AlterTable(const AlterTableRequestPB& req,
Status::NotFound("the table was deleted", l.data().pb.state_msg()),
resp, MasterErrorPB::TABLE_NOT_FOUND);
}
l.mutable_data()->pb.set_alter_timestamp(time(nullptr));

string normalized_table_name = NormalizeTableName(l.data().name());
*resp->mutable_table_id() = table->id();
Expand Down
5 changes: 5 additions & 0 deletions src/kudu/master/master.proto
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ message SysTablesEntryPB {
// Debug state for the table.
optional State state = 6 [ default = UNKNOWN ];
optional bytes state_msg = 7;

// The create time of the table, in seconds since the epoch.
optional int64 create_timestamp = 10;
// The last alter time of the table, in seconds since the epoch.
optional int64 alter_timestamp = 11;
}

// The on-disk entry in the sys.catalog table ("metadata" column) to represent
Expand Down
13 changes: 13 additions & 0 deletions src/kudu/master/master_path_handlers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "kudu/gutil/strings/join.h"
#include "kudu/gutil/strings/numbers.h"
#include "kudu/gutil/strings/substitute.h"
#include "kudu/gutil/walltime.h"
#include "kudu/master/catalog_manager.h"
#include "kudu/master/master.h"
#include "kudu/master/master.pb.h"
Expand Down Expand Up @@ -198,6 +199,18 @@ void MasterPathHandlers::HandleCatalogManager(const Webserver::WebRequest& req,
table_json["id"] = EscapeForHtmlToString(table->id());
table_json["state"] = state;
table_json["message"] = EscapeForHtmlToString(l.data().pb.state_msg());
std::string str_create_time;
if (l.data().pb.has_create_timestamp()) {
StringAppendStrftime(&str_create_time, "%Y-%m-%d %H:%M:%S %Z",
l.data().pb.create_timestamp(), true);
}
table_json["create time"] = EscapeForHtmlToString(str_create_time);
std::string str_alter_time;
if (l.data().pb.has_alter_timestamp()) {
StringAppendStrftime(&str_alter_time, "%Y-%m-%d %H:%M:%S %Z",
l.data().pb.alter_timestamp(), true);
}
table_json["alter time"] = EscapeForHtmlToString(str_alter_time);
}
(*output).Set<int64_t>("num_tables", num_running_tables);
}
Expand Down
4 changes: 4 additions & 0 deletions www/tables.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ There are {{num_tables}} tables.
<th>Table Id</th>
<th>State</th>
<th>State Message</th>
<th>Create Time</th>
<th>Last Alter Time</th>
</tr></thead>
<tbody>
{{#tables}}
Expand All @@ -42,6 +44,8 @@ There are {{num_tables}} tables.
<td><a href="/table?id={{id}}">{{id}}</a></td>
<td>{{state}}</td>
<td>{{message}}</td>
<td>{{create time}}</td>
<td>{{alter time}}</td>
</tr>
{{/tables}}
</tbody>
Expand Down

0 comments on commit 4127186

Please sign in to comment.