Skip to content

Commit c29cac7

Browse files
committed
Revert most of "[ThinLTO] Async CAS cache write"
1 parent 2abb741 commit c29cac7

File tree

15 files changed

+15
-196
lines changed

15 files changed

+15
-196
lines changed

llvm/include/llvm-c/CAS/PluginAPI_functions.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,6 @@ LLCAS_PUBLIC bool llcas_cas_store_object(llcas_cas_t, llcas_data_t,
249249
const llcas_objectid_t *refs,
250250
size_t refs_count,
251251
llcas_objectid_t *p_id, char **error);
252-
/**
253-
* Like \c llcas_cas_store_object but storing happens via a callback function.
254-
* Whether the call is asynchronous or not depends on the implementation.
255-
*
256-
* \param ctx_cb pointer to pass to the callback function.
257-
*/
258-
LLCAS_PUBLIC void llcas_cas_store_object_async(llcas_cas_t, llcas_data_t,
259-
const llcas_objectid_t *refs,
260-
size_t refs_count, void *ctx_cb,
261-
llcas_cas_store_object_cb);
262252

263253
/**
264254
* \returns the data buffer of the provided \c llcas_loaded_object_t. The buffer

llvm/include/llvm-c/CAS/PluginAPI_types.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,6 @@ typedef enum {
9494
typedef void (*llcas_cas_load_object_cb)(void *ctx, llcas_lookup_result_t,
9595
llcas_loaded_object_t, char *error);
9696

97-
/**
98-
* Callback for \c llcas_cas_store_object_async.
99-
*
100-
* \param ctx pointer passed through from the \c llcas_cas_store_object_async
101-
* call.
102-
* \param error message if an error occurred. If set, the memory it points to
103-
* needs to be released via \c llcas_string_dispose.
104-
*/
105-
typedef void (*llcas_cas_store_object_cb)(void *ctx, bool, llcas_objectid_t,
106-
char *error);
107-
10897
/**
10998
* Callback for \c llcas_actioncache_get_for_digest_async.
11099
*

llvm/include/llvm/CAS/ObjectStore.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,6 @@ class ObjectStore {
143143
/// Store object into ObjectStore.
144144
virtual Expected<ObjectRef> store(ArrayRef<ObjectRef> Refs,
145145
ArrayRef<char> Data) = 0;
146-
/// Async version of \c store using a callback.
147-
virtual void
148-
storeAsync(ArrayRef<ObjectRef> Refs, ArrayRef<char> Data,
149-
unique_function<void(Expected<ObjectRef>)> Callback) = 0;
150-
151146
/// Get an ID for \p Ref.
152147
virtual CASID getID(ObjectRef Ref) const = 0;
153148

@@ -226,9 +221,6 @@ class ObjectStore {
226221
public:
227222
/// Helper functions to store object and returns a ObjectProxy.
228223
Expected<ObjectProxy> createProxy(ArrayRef<ObjectRef> Refs, StringRef Data);
229-
/// Async version of \c createProxy using a callback.
230-
void createProxyAsync(ArrayRef<ObjectRef> Refs, StringRef Data,
231-
unique_function<void(Expected<ObjectProxy>)> Callback);
232224

233225
/// Store object from StringRef.
234226
Expected<ObjectRef> storeFromString(ArrayRef<ObjectRef> Refs,

llvm/include/llvm/RemoteCachingService/Client.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,6 @@ class CASDBClient {
244244
return putFileSyncImpl(std::move(FilePath), Refs);
245245
}
246246

247-
using PutCb = std::function<void(Expected<std::string>)>;
248-
virtual void putDataAsync(std::string BlobData, ArrayRef<std::string> Refs,
249-
PutCb Callback) {
250-
return putDataAsyncImpl(std::move(BlobData), Refs, std::move(Callback));
251-
}
252-
253247
protected:
254248
virtual Expected<LoadResponse>
255249
loadSyncImpl(std::string CASID, std::optional<std::string> OutFilePath) = 0;
@@ -267,8 +261,6 @@ class CASDBClient {
267261
ArrayRef<std::string> Refs) = 0;
268262
virtual Expected<std::string> putFileSyncImpl(std::string FilePath,
269263
ArrayRef<std::string> Refs) = 0;
270-
virtual void putDataAsyncImpl(std::string BlobData,
271-
ArrayRef<std::string> Refs, PutCb Callback) = 0;
272264

273265
public:
274266
class LoadAsyncQueue : public AsyncQueueBase {

llvm/lib/CAS/BuiltinCAS.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "BuiltinCAS.h"
10-
#include "llvm/ADT/FunctionExtras.h"
1110
#include "llvm/ADT/StringExtras.h"
1211
#include "llvm/CAS/BuiltinObjectHasher.h"
1312
#include "llvm/CAS/UnifiedOnDiskCache.h"
@@ -72,13 +71,6 @@ Expected<ObjectRef> BuiltinCAS::store(ArrayRef<ObjectRef> Refs,
7271
Refs, Data);
7372
}
7473

75-
void BuiltinCAS::storeAsync(
76-
ArrayRef<ObjectRef> Refs, ArrayRef<char> Data,
77-
unique_function<void(Expected<ObjectRef>)> Callback) {
78-
// Just do it synchronously.
79-
return Callback(store(Refs, Data));
80-
}
81-
8274
Error BuiltinCAS::validate(const CASID &ID) {
8375
auto Ref = getReference(ID);
8476
if (!Ref)

llvm/lib/CAS/BuiltinCAS.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class BuiltinCAS : public ObjectStore {
3030

3131
Expected<ObjectRef> store(ArrayRef<ObjectRef> Refs,
3232
ArrayRef<char> Data) final;
33-
void storeAsync(ArrayRef<ObjectRef> Refs, ArrayRef<char> Data,
34-
unique_function<void(Expected<ObjectRef>)> Callback) final;
3533
virtual Expected<ObjectRef> storeImpl(ArrayRef<uint8_t> ComputedHash,
3634
ArrayRef<ObjectRef> Refs,
3735
ArrayRef<char> Data) = 0;

llvm/lib/CAS/ObjectStore.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,6 @@ Expected<ObjectProxy> ObjectStore::createProxy(ArrayRef<ObjectRef> Refs,
168168
return getProxy(*Ref);
169169
}
170170

171-
void ObjectStore::createProxyAsync(
172-
ArrayRef<ObjectRef> Refs, StringRef Data,
173-
unique_function<void(Expected<ObjectProxy>)> Callback) {
174-
storeAsync(
175-
Refs, arrayRefFromStringRef<char>(Data),
176-
[this, Callback = std::move(Callback)](Expected<ObjectRef> Ref) mutable {
177-
if (!Ref)
178-
return Callback(Ref.takeError());
179-
return Callback(getProxy(*Ref));
180-
});
181-
}
182-
183171
Expected<ObjectRef>
184172
ObjectStore::storeFromOpenFileImpl(sys::fs::file_t FD,
185173
std::optional<sys::fs::file_status> Status) {

llvm/lib/CAS/PluginAPI.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ struct llcas_functions_t {
6767
const llcas_objectid_t *refs, size_t refs_count,
6868
llcas_objectid_t *, char **error);
6969

70-
void (*cas_store_object_async)(llcas_cas_t, llcas_data_t,
71-
const llcas_objectid_t *refs,
72-
size_t refs_count, void *ctx_cb,
73-
llcas_cas_store_object_cb);
74-
7570
llcas_data_t (*loaded_object_get_data)(llcas_cas_t, llcas_loaded_object_t);
7671

7772
llcas_object_refs_t (*loaded_object_get_refs)(llcas_cas_t,

llvm/lib/CAS/PluginAPI_functions.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ CASPLUGINAPI_FUNCTION(cas_options_set_option, true)
2323
CASPLUGINAPI_FUNCTION(cas_prune_ondisk_data, false)
2424
CASPLUGINAPI_FUNCTION(cas_set_ondisk_size_limit, false)
2525
CASPLUGINAPI_FUNCTION(cas_store_object, true)
26-
CASPLUGINAPI_FUNCTION(cas_store_object_async, true)
2726
CASPLUGINAPI_FUNCTION(digest_parse, true)
2827
CASPLUGINAPI_FUNCTION(digest_print, true)
2928
CASPLUGINAPI_FUNCTION(get_plugin_version, true)

llvm/lib/CAS/PluginCAS.cpp

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ class PluginObjectStore
128128
Expected<CASID> parseID(StringRef ID) final;
129129
Expected<ObjectRef> store(ArrayRef<ObjectRef> Refs,
130130
ArrayRef<char> Data) final;
131-
void storeAsync(ArrayRef<ObjectRef> Refs, ArrayRef<char> Data,
132-
unique_function<void(Expected<ObjectRef>)> Callback) final;
133131
CASID getID(ObjectRef Ref) const final;
134132
std::optional<ObjectRef> getReference(const CASID &ID) const final;
135133
Expected<bool> isMaterialized(ObjectRef Ref) const final;
@@ -210,40 +208,6 @@ Expected<ObjectRef> PluginObjectStore::store(ArrayRef<ObjectRef> Refs,
210208
return ObjectRef::getFromInternalRef(*this, c_stored_id.opaque);
211209
}
212210

213-
void PluginObjectStore::storeAsync(
214-
ArrayRef<ObjectRef> Refs, ArrayRef<char> Data,
215-
unique_function<void(Expected<ObjectRef>)> Callback) {
216-
SmallVector<llcas_objectid_t, 64> c_ids;
217-
c_ids.reserve(Refs.size());
218-
for (ObjectRef Ref : Refs) {
219-
c_ids.push_back(llcas_objectid_t{Ref.getInternalRef(*this)});
220-
}
221-
222-
struct ObjectStoreCtx {
223-
std::shared_ptr<PluginObjectStore> DB;
224-
unique_function<void(Expected<ObjectRef>)> Callback;
225-
};
226-
auto ObjectStoreCB = [](void *c_ctx, bool c_has_error,
227-
llcas_objectid_t c_stored_id, char *c_err) {
228-
auto getRefAndDispose = [&](ObjectStoreCtx *Ctx) -> Expected<ObjectRef> {
229-
auto _ = make_scope_exit([Ctx]() { delete Ctx; });
230-
if (c_has_error)
231-
return Ctx->DB->Ctx->errorAndDispose(c_err);
232-
return ObjectRef::getFromInternalRef(*Ctx->DB, c_stored_id.opaque);
233-
};
234-
235-
ObjectStoreCtx *Ctx = static_cast<ObjectStoreCtx *>(c_ctx);
236-
auto Callback = std::move(Ctx->Callback);
237-
Callback(getRefAndDispose(Ctx));
238-
};
239-
240-
ObjectStoreCtx *CallCtx =
241-
new ObjectStoreCtx{shared_from_this(), std::move(Callback)};
242-
Ctx->Functions.cas_store_object_async(
243-
Ctx->c_cas, llcas_data_t{Data.data(), Data.size()}, c_ids.data(),
244-
c_ids.size(), CallCtx, ObjectStoreCB);
245-
}
246-
247211
static StringRef toStringRef(llcas_digest_t c_digest) {
248212
return StringRef((const char *)c_digest.data, c_digest.size);
249213
}

llvm/lib/LTO/ThinLTOCodeGenerator.cpp

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -596,40 +596,28 @@ class CASModuleCacheEntry : public ModuleCacheEntry {
596596
}
597597

598598
void write(const MemoryBuffer &OutputBuffer, std::function<void()> Cb) final {
599-
auto SaveStart = std::chrono::steady_clock::now();
600-
CAS.createProxyAsync({}, OutputBuffer.getBuffer(), [=](auto MaybeProxy) {
599+
std::optional<cas::ObjectProxy> Proxy;
600+
if (Error E =
601+
CAS.createProxy({}, OutputBuffer.getBuffer()).moveInto(Proxy)) {
602+
handleCASError(std::move(E), Logger);
603+
return Cb();
604+
}
605+
606+
auto UpdateStart = std::chrono::steady_clock::now();
607+
Cache.putAsync(ID, Proxy->getID(), /*Globally=*/true, [=](auto Err) {
601608
if (Logger) {
602-
auto SaveEnd = std::chrono::steady_clock::now();
609+
auto UpdateEnd = std::chrono::steady_clock::now();
603610
auto Seconds =
604-
std::chrono::duration<double>(SaveEnd - SaveStart).count();
611+
std::chrono::duration<double>(UpdateEnd - UpdateStart).count();
605612
Logger([&](raw_ostream &OS) {
606-
OS << "LTO cache save '" << ID << "' in "
613+
OS << "LTO cache update '" << ID << "' in "
607614
<< llvm::format("%.6fs", Seconds) << "\n";
608615
});
609616
}
610617

611-
std::optional<cas::ObjectProxy> Proxy;
612-
if (Error E = std::move(MaybeProxy).moveInto(Proxy)) {
613-
handleCASError(std::move(E), Logger);
614-
return Cb();
615-
}
616-
617-
auto UpdateStart = std::chrono::steady_clock::now();
618-
Cache.putAsync(ID, Proxy->getID(), /*Globally=*/true, [=](auto Err) {
619-
if (Logger) {
620-
auto UpdateEnd = std::chrono::steady_clock::now();
621-
auto Seconds =
622-
std::chrono::duration<double>(UpdateEnd - UpdateStart).count();
623-
Logger([&](raw_ostream &OS) {
624-
OS << "LTO cache update '" << ID << "' in "
625-
<< llvm::format("%.6fs", Seconds) << "\n";
626-
});
627-
}
628-
629-
if (Err)
630-
report_fatal_error(std::move(Err));
631-
Cb();
632-
});
618+
if (Err)
619+
report_fatal_error(std::move(Err));
620+
Cb();
633621
});
634622
}
635623

llvm/lib/RemoteCachingService/CAS/GRPCRelayCAS.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ class GRPCRelayCAS : public ObjectStore {
114114
Expected<CASID> parseID(StringRef ID) final;
115115
Expected<ObjectRef> store(ArrayRef<ObjectRef> Refs,
116116
ArrayRef<char> Data) final;
117-
void storeAsync(ArrayRef<ObjectRef> Refs, ArrayRef<char> Data,
118-
unique_function<void(Expected<ObjectRef>)> Callback) override;
119117
CASID getID(ObjectRef Ref) const final;
120118
std::optional<ObjectRef> getReference(const CASID &ID) const final;
121119
Expected<bool> isMaterialized(ObjectRef Ref) const final;
@@ -294,27 +292,6 @@ Expected<ObjectRef> GRPCRelayCAS::store(ArrayRef<ObjectRef> Refs,
294292
return toReference(storeObjectImpl(I, InternalRefs, Data));
295293
}
296294

297-
void GRPCRelayCAS::storeAsync(
298-
ArrayRef<ObjectRef> Refs, ArrayRef<char> Data,
299-
unique_function<void(Expected<ObjectRef>)> Callback) {
300-
SmallVector<std::string> RefIDs;
301-
for (auto Ref : Refs)
302-
RefIDs.emplace_back(getDataIDFromRef(Ref));
303-
304-
CASDB->putDataAsync(toStringRef(Data).str(), RefIDs, [&](auto Response) {
305-
if (!Response)
306-
return Callback(Response.takeError());
307-
308-
auto &I = indexHash(arrayRefFromStringRef(*Response));
309-
// Create the node.
310-
SmallVector<const InMemoryIndexValueT *> InternalRefs;
311-
for (ObjectRef Ref : Refs)
312-
InternalRefs.push_back(&asInMemoryIndexValue(Ref));
313-
314-
return Callback(toReference(storeObjectImpl(I, InternalRefs, Data)));
315-
});
316-
}
317-
318295
CASID GRPCRelayCAS::getID(ObjectRef Ref) const {
319296
return getID(asInMemoryIndexValue(Ref));
320297
}

llvm/lib/RemoteCachingService/Client/Client.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -676,17 +676,6 @@ class CASDBClientImpl : public CASDBClient {
676676
return casPutSync(Request);
677677
}
678678

679-
void putDataAsyncImpl(std::string BlobData, ArrayRef<std::string> Refs,
680-
PutCb Callback) override {
681-
CASPutRequest Request;
682-
Request.mutable_data()->mutable_blob()->set_data(std::move(BlobData));
683-
for (auto &Ref : Refs) {
684-
CASDataID *NewRef = Request.mutable_data()->add_references();
685-
NewRef->set_id(Ref);
686-
}
687-
return casPutAsync(std::move(Request), std::move(Callback));
688-
}
689-
690679
Expected<std::string> putFileSyncImpl(std::string FilePath,
691680
ArrayRef<std::string> Refs) override {
692681
assert(!FilePath.empty());
@@ -712,26 +701,6 @@ class CASDBClientImpl : public CASDBClient {
712701
return Response.cas_id().id();
713702
}
714703

715-
void casPutAsync(CASPutRequest Request,
716-
std::function<void(Expected<std::string>)> Callback) {
717-
auto Context = std::make_shared<grpc::ClientContext>();
718-
auto Response = std::make_shared<CASPutResponse>();
719-
auto Req = std::make_shared<CASPutRequest>(std::move(Request));
720-
Stub->async()->Put(
721-
&*Context, &*Req, Response.get(), [&](grpc::Status Status) mutable {
722-
(void)Context;
723-
(void)Req;
724-
725-
if (!Status.ok())
726-
return Callback(errorFromGRPCStatus(Status));
727-
728-
if (Response->has_error())
729-
return Callback(createStringError(inconvertibleErrorCode(),
730-
Response->error().description()));
731-
return Callback(Response->cas_id().id());
732-
});
733-
}
734-
735704
public:
736705
CASDBClientImpl(std::shared_ptr<grpc::Channel> Channel)
737706
: Stub(CASDBService::NewStub(std::move(Channel))) {

llvm/tools/libCASPluginTest/libCASPluginTest.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -486,19 +486,6 @@ bool llcas_cas_store_object(llcas_cas_t c_cas, llcas_data_t c_data,
486486
return false;
487487
}
488488

489-
void llcas_cas_store_object_async(llcas_cas_t c_cas, llcas_data_t c_data,
490-
const llcas_objectid_t *c_refs,
491-
size_t c_refs_count, void *ctx_cb,
492-
llcas_cas_store_object_cb cb) {
493-
unwrap(c_cas)->Pool.async([&] {
494-
llcas_objectid_t id;
495-
char *error;
496-
bool has_error = llcas_cas_store_object(c_cas, c_data, c_refs, c_refs_count,
497-
&id, &error);
498-
cb(ctx_cb, has_error, id, error);
499-
});
500-
}
501-
502489
llcas_data_t llcas_loaded_object_get_data(llcas_cas_t c_cas,
503490
llcas_loaded_object_t c_obj) {
504491
auto &CAS = unwrap(c_cas)->DB->getGraphDB();

llvm/tools/libCASPluginTest/libCASPluginTest.exports

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ llcas_cas_options_set_option
1818
llcas_cas_prune_ondisk_data
1919
llcas_cas_set_ondisk_size_limit
2020
llcas_cas_store_object
21-
llcas_cas_store_object_async
2221
llcas_digest_parse
2322
llcas_digest_print
2423
llcas_get_plugin_version

0 commit comments

Comments
 (0)