This is an automated email from the ASF dual-hosted git repository.
gavinchou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new a4371c2f6d7 [fix](recycler) Fix incorrect mtime convertion in azure
obj client (#37535)
a4371c2f6d7 is described below
commit a4371c2f6d7e88fd25d80de36628bd2836e3bbfb
Author: plat1ko <[email protected]>
AuthorDate: Fri Jul 12 12:54:55 2024 +0800
[fix](recycler) Fix incorrect mtime convertion in azure obj client (#37535)
---
cloud/src/recycler/azure_obj_client.cpp | 10 +++++++++-
cloud/test/s3_accessor_test.cpp | 4 ++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/cloud/src/recycler/azure_obj_client.cpp
b/cloud/src/recycler/azure_obj_client.cpp
index 614bf3dc236..b983ab3c441 100644
--- a/cloud/src/recycler/azure_obj_client.cpp
+++ b/cloud/src/recycler/azure_obj_client.cpp
@@ -21,6 +21,7 @@
#include <glog/logging.h>
#include <algorithm>
+#include <azure/core/datetime.hpp>
#include <azure/core/io/body_stream.hpp>
#include <azure/storage/blobs.hpp>
#include <azure/storage/blobs/blob_client.hpp>
@@ -61,6 +62,8 @@ ObjectStorageResponse do_azure_client_call(Func f,
std::string_view url, std::st
return {};
}
+static const Azure::DateTime SystemClockEpoch {1970, 1, 1};
+
class AzureListIterator final : public ObjectListIterator {
public:
AzureListIterator(std::shared_ptr<BlobContainerClient> client, std::string
prefix)
@@ -96,7 +99,12 @@ public:
results_.emplace_back(ObjectMeta {
.key = std::move(item.Name),
.size = item.BlobSize,
- .mtime_s =
item.Details.LastModified.time_since_epoch().count()});
+ // `Azure::DateTime` adds the offset of
`SystemClockEpoch` to the given Unix timestamp,
+ // so here we need to subtract this offset to obtain
the Unix timestamp of the mtime.
+ //
https://github.com/Azure/azure-sdk-for-cpp/blob/azure-core_1.12.0/sdk/core/azure-core/inc/azure/core/datetime.hpp#L129
+ .mtime_s =
duration_cast<std::chrono::seconds>(item.Details.LastModified -
+
SystemClockEpoch)
+ .count()});
}
} catch (Azure::Storage::StorageException& e) {
LOG_WARNING(
diff --git a/cloud/test/s3_accessor_test.cpp b/cloud/test/s3_accessor_test.cpp
index c1d1acd4468..0dd51b749d8 100644
--- a/cloud/test/s3_accessor_test.cpp
+++ b/cloud/test/s3_accessor_test.cpp
@@ -22,6 +22,7 @@
#include <gtest/gtest.h>
#include <azure/storage/blobs/blob_options.hpp>
+#include <chrono>
#include <unordered_set>
#include "common/config.h"
@@ -138,7 +139,10 @@ void test_s3_accessor(S3Accessor& accessor) {
ret = accessor.list_all(&iter);
ASSERT_EQ(ret, 0);
list_files.clear();
+ using namespace std::chrono;
+ int64_t now =
duration_cast<seconds>(system_clock::now().time_since_epoch()).count();
for (auto file = iter->next(); file.has_value(); file = iter->next()) {
+ EXPECT_LT(now - file->mtime_s, 60);
list_files.insert(std::move(file->path));
}
ASSERT_EQ(list_files.size(), files.size());
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]