acelyc111 commented on code in PR #1667:
URL:
https://github.com/apache/incubator-pegasus/pull/1667#discussion_r1382915847
##########
src/replica/disk_cleaner.cpp:
##########
@@ -70,6 +75,108 @@ const std::string kFolderSuffixBak = ".bak";
const std::string kFolderSuffixOri = ".ori";
const std::string kFolderSuffixTmp = ".tmp";
+namespace {
+
+// TODO(wangdan): we could study later whether ctime (i.e. `st_ctime` within
`struct stat`,
+// the time of last status change) could be used instead of mtime (i.e.
`st_ctime` within
+// `struct stat`, the last write time), since ctime of the new directory would
be updated
+// to the current time once rename() is called, while mtime would not be
updated.
+bool get_expiration_timestamp_by_last_write_time(const std::string &path,
+ uint64_t delay_seconds,
+ uint64_t
&expiration_timestamp_s)
+{
+ time_t last_write_time_s;
+ if (!dsn::utils::filesystem::last_write_time(path, last_write_time_s)) {
+ LOG_WARNING("gc_disk: failed to get last write time of {}", path);
+ return false;
+ }
+
+ expiration_timestamp_s = static_cast<uint64_t>(last_write_time_s) +
delay_seconds;
+ return true;
+}
+
+// Unix timestamp in microseconds for 2010-01-01 00:00:00.
Review Comment:
nit: note which time zone (CST) it is.
##########
src/replica/disk_cleaner.cpp:
##########
@@ -70,6 +75,108 @@ const std::string kFolderSuffixBak = ".bak";
const std::string kFolderSuffixOri = ".ori";
const std::string kFolderSuffixTmp = ".tmp";
+namespace {
+
+// TODO(wangdan): we could study later whether ctime (i.e. `st_ctime` within
`struct stat`,
+// the time of last status change) could be used instead of mtime (i.e.
`st_ctime` within
+// `struct stat`, the last write time), since ctime of the new directory would
be updated
+// to the current time once rename() is called, while mtime would not be
updated.
+bool get_expiration_timestamp_by_last_write_time(const std::string &path,
+ uint64_t delay_seconds,
+ uint64_t
&expiration_timestamp_s)
+{
+ time_t last_write_time_s;
+ if (!dsn::utils::filesystem::last_write_time(path, last_write_time_s)) {
+ LOG_WARNING("gc_disk: failed to get last write time of {}", path);
+ return false;
+ }
+
+ expiration_timestamp_s = static_cast<uint64_t>(last_write_time_s) +
delay_seconds;
+ return true;
+}
+
+// Unix timestamp in microseconds for 2010-01-01 00:00:00.
+// This timestamp could be used as the minimum, since it's far earlier than
the time when
+// Pegasus was born.
+#define MIN_TIMESTAMP_US 1262275200000000
+#define MIN_TIMESTAMP_US_LENGTH (sizeof(STRINGIFY(MIN_TIMESTAMP_US)) - 1)
+
+// Parse timestamp from the directory name.
+//
+// There are only 2 kinds of directory names that could include timestamp: one
is the faulty
+// replicas whose name has suffix ".err"; another is the dropped replicas
whose name has
+// suffix ".gar". The examples for both kinds of directory names:
+// 1.1.pegasus.1698843209235962.err
+// 1.2.pegasus.1698843214240709.gar
+//
+// Specify the size of suffix by `suffix_size`. For both kinds of names (.err
and .gar),
+// `suffix_size` is 4.
+//
+// The timestamp is the number the number just before the suffix, between the
2 dots. For
Review Comment:
Duplicate `the number`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]