This is an automated email from the ASF dual-hosted git repository. adar pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kudu.git
commit 4127186583c1110d01e906a0eda49989dd26ac34 Author: helifu <[email protected]> AuthorDate: Mon Mar 25 12:38:44 2019 +0800 KUDU-2750: Add create and alter timestamp to tables 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 --- src/kudu/master/catalog_manager.cc | 3 +++ src/kudu/master/master.proto | 5 +++++ src/kudu/master/master_path_handlers.cc | 13 +++++++++++++ www/tables.mustache | 4 ++++ 4 files changed, 25 insertions(+) diff --git a/src/kudu/master/catalog_manager.cc b/src/kudu/master/catalog_manager.cc index 660c3d5..ed5d583 100644 --- a/src/kudu/master/catalog_manager.cc +++ b/src/kudu/master/catalog_manager.cc @@ -53,6 +53,7 @@ #include <ostream> #include <set> #include <string> +#include <time.h> #include <type_traits> #include <unordered_map> #include <unordered_set> @@ -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; } @@ -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(); diff --git a/src/kudu/master/master.proto b/src/kudu/master/master.proto index dd73a39..30cbcc8 100644 --- a/src/kudu/master/master.proto +++ b/src/kudu/master/master.proto @@ -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 diff --git a/src/kudu/master/master_path_handlers.cc b/src/kudu/master/master_path_handlers.cc index 02e6474..2a128b3 100644 --- a/src/kudu/master/master_path_handlers.cc +++ b/src/kudu/master/master_path_handlers.cc @@ -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" @@ -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); } diff --git a/www/tables.mustache b/www/tables.mustache index 0523aa3..964f21e 100644 --- a/www/tables.mustache +++ b/www/tables.mustache @@ -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}} @@ -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>
