forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathIObjectStorage.cpp
More file actions
157 lines (132 loc) · 4.79 KB
/
IObjectStorage.cpp
File metadata and controls
157 lines (132 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <Disks/IO/ThreadPoolRemoteFSReader.h>
#include <Disks/DiskObjectStorage/ObjectStorages/IObjectStorage.h>
#include <Disks/DiskObjectStorage/ObjectStorages/ObjectStorageIterator.h>
#include <IO/ReadBufferFromFileBase.h>
#include <IO/WriteBufferFromFileBase.h>
#include <IO/copyData.h>
#include <Interpreters/Context.h>
#include <Common/Exception.h>
#include <Common/ObjectStorageKeyGenerator.h>
#include <IO/WriteBufferFromString.h>
#include <Storages/ObjectStorage/DataLakes/IDataLakeMetadata.h>
#include <Poco/JSON/Object.h>
#include <Poco/JSON/Parser.h>
#include <Poco/JSON/JSONException.h>
namespace DB
{
namespace ErrorCodes
{
extern const int NOT_IMPLEMENTED;
extern const int LOGICAL_ERROR;
}
bool IObjectStorage::existsOrHasAnyChild(const std::string & path) const
{
RelativePathsWithMetadata files;
listObjects(path, files, 1);
return !files.empty();
}
void IObjectStorage::listObjects(const std::string &, RelativePathsWithMetadata &, size_t) const
{
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "listObjects() is not supported");
}
/// Read single object
SmallObjectDataWithMetadata IObjectStorage::readSmallObjectAndGetObjectMetadata( /// NOLINT
const StoredObject & object,
const ReadSettings & read_settings,
size_t max_size_bytes,
std::optional<size_t> read_hint) const
{
auto buffer = readObject(object, read_settings, read_hint);
SmallObjectDataWithMetadata result;
WriteBufferFromString out(result.data);
copyDataMaxBytes(*buffer, out, max_size_bytes);
out.finalize();
/// By default no metadata available, derived classes may override this method
return result;
}
ObjectStorageIteratorPtr IObjectStorage::iterate(const std::string & path_prefix, size_t max_keys, bool) const
{
RelativePathsWithMetadata files;
listObjects(path_prefix, files, max_keys);
return std::make_shared<ObjectStorageIteratorFromList>(std::move(files));
}
ThreadPool & IObjectStorage::getThreadPoolWriter()
{
auto context = Context::getGlobalContextInstance();
if (!context)
throw Exception(ErrorCodes::LOGICAL_ERROR, "Global context not initialized");
return context->getThreadPoolWriter();
}
void IObjectStorage::copyObjectToAnotherObjectStorage( // NOLINT
const StoredObject & object_from,
const StoredObject & object_to,
const ReadSettings & read_settings,
const WriteSettings & write_settings,
IObjectStorage & object_storage_to,
std::optional<ObjectAttributes> object_to_attributes)
{
if (&object_storage_to == this)
copyObject(object_from, object_to, read_settings, write_settings, object_to_attributes);
auto in = readObject(object_from, read_settings);
auto out = object_storage_to.writeObject(object_to, WriteMode::Rewrite, /* attributes= */ {}, /* buf_size= */ DBMS_DEFAULT_BUFFER_SIZE, write_settings);
copyData(*in, *out);
out->finalize();
}
const std::string & IObjectStorage::getCacheName() const
{
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "getCacheName is not implemented for object storage");
}
ReadSettings IObjectStorage::patchSettings(const ReadSettings & read_settings) const
{
return read_settings;
}
WriteSettings IObjectStorage::patchSettings(const WriteSettings & write_settings) const
{
return write_settings;
}
RelativePathWithMetadata::RelativePathWithMetadata(const DataFileInfo & info, std::optional<ObjectMetadata> metadata_)
: metadata(std::move(metadata_))
{
relative_path = info.file_path;
file_meta_info = info.file_meta_info;
}
RelativePathWithMetadata::CommandInTaskResponse::CommandInTaskResponse(const std::string & task)
{
Poco::JSON::Parser parser;
try
{
auto json = parser.parse(task).extract<Poco::JSON::Object::Ptr>();
if (!json)
return;
is_valid = true;
if (json->has("file_path"))
file_path = json->getValue<std::string>("file_path");
if (json->has("retry_after_us"))
retry_after_us = json->getValue<size_t>("retry_after_us");
if (json->has("meta_info"))
file_meta_info = std::make_shared<DataFileMetaInfo>(json->getObject("meta_info"));
}
catch (const Poco::JSON::JSONException &)
{ /// Not a JSON
return;
}
catch (const Poco::SyntaxException &)
{ /// Not a JSON
return;
}
}
std::string RelativePathWithMetadata::CommandInTaskResponse::toString() const
{
Poco::JSON::Object json;
if (file_path.has_value())
json.set("file_path", file_path.value());
if (retry_after_us.has_value())
json.set("retry_after_us", retry_after_us.value());
if (file_meta_info.has_value())
json.set("meta_info", file_meta_info.value()->toJson());
std::ostringstream oss;
oss.exceptions(std::ios::failbit);
Poco::JSON::Stringifier::stringify(json, oss);
return oss.str();
}
}