libstore: add worker serializer for SubstitutablePathInfo

the test is for the map that usually wraps it though because it's the
bit we're interested in replacing, and it has custom serializer code.

Change-Id: If77a236dfca738b646ed2b7a5c65515dad6b7295
This commit is contained in:
eldritch horrors
2025-06-06 18:09:46 +02:00
parent fca0a30470
commit dd31a23c31
7 changed files with 63 additions and 18 deletions
+1 -7
View File
@@ -682,13 +682,7 @@ static void performOp(AsyncIoRoot & aio, TunnelLogger * logger, ref<Store> store
logger->startWork();
aio.blockOn(store->querySubstitutablePathInfos(pathsMap, infos));
logger->stopWork();
to << infos.size();
for (auto & i : infos) {
to << store->printStorePath(i.first)
<< (i.second.deriver ? store->printStorePath(*i.second.deriver) : "");
to << WorkerProto::write(*store, wconn, i.second.references);
to << i.second.downloadSize << i.second.narSize;
}
to << WorkerProto::write(*store, wconn, infos);
break;
}
+3
View File
@@ -27,6 +27,9 @@ struct SubstitutablePathInfo
* 0 = unknown
*/
uint64_t narSize;
bool operator==(const SubstitutablePathInfo &) const = default;
bool operator!=(const SubstitutablePathInfo &) const = default;
};
using SubstitutablePathInfos = std::map<StorePath, SubstitutablePathInfo>;
+2 -11
View File
@@ -23,6 +23,7 @@
#include "lix/libutil/thread-name.hh"
#include "lix/libutil/thread-pool.hh"
#include "lix/libutil/types.hh"
#include "path-info.hh"
#include <kj/async.h>
#include <optional>
@@ -240,17 +241,7 @@ try {
conn->to << WorkerProto::Op::QuerySubstitutablePathInfos;
conn->to << WorkerProto::write(*this, *conn, pathsMap);
conn.processStderr();
size_t count = readNum<size_t>(conn->from);
for (size_t n = 0; n < count; n++) {
SubstitutablePathInfo & info(infos[parseStorePath(readString(conn->from))]);
auto deriver = readString(conn->from);
if (deriver != "")
info.deriver = parseStorePath(deriver);
info.references = WorkerProto::Serialise<StorePathSet>::read(*this, *conn);
info.downloadSize = readLongLong(conn->from);
info.narSize = readLongLong(conn->from);
}
infos = WorkerProto::Serialise<SubstitutablePathInfos>::read(*this, *conn);
co_return result::success();
} catch (...) {
co_return result::current_exception();
+21
View File
@@ -152,4 +152,25 @@ WireFormatGenerator WorkerProto::Serialise<UnkeyedValidPathInfo>::write(const St
co_yield renderContentAddress(pathInfo.ca);
}
SubstitutablePathInfo WorkerProto::Serialise<SubstitutablePathInfo>::read(const Store & store, ReadConn conn)
{
SubstitutablePathInfo info;
auto deriver = readString(conn.from);
if (deriver != "")
info.deriver = store.parseStorePath(deriver);
info.references = WorkerProto::Serialise<StorePathSet>::read(store, conn);
info.downloadSize = readLongLong(conn.from);
info.narSize = readLongLong(conn.from);
return info;
}
WireFormatGenerator WorkerProto::Serialise<SubstitutablePathInfo>::write(const Store & store, WriteConn conn, const SubstitutablePathInfo & info)
{
co_yield (info.deriver ? store.printStorePath(*info.deriver) : "");
co_yield WorkerProto::write(store, conn, info.references);
co_yield info.downloadSize;
co_yield info.narSize;
}
}
+3
View File
@@ -2,6 +2,7 @@
///@file
#include "lix/libstore/common-protocol.hh"
#include "path-info.hh"
namespace nix {
@@ -230,6 +231,8 @@ template<>
DECLARE_WORKER_SERIALISER(UnkeyedValidPathInfo);
template<>
DECLARE_WORKER_SERIALISER(std::optional<TrustedFlag>);
template<>
DECLARE_WORKER_SERIALISER(SubstitutablePathInfo);
template<typename T>
DECLARE_WORKER_SERIALISER(std::vector<T>);
+33
View File
@@ -3,6 +3,7 @@
#include <gtest/gtest.h>
#include "lix/libstore/worker-protocol.hh"
#include "lix/libstore/path-info.hh"
#include "lix/libstore/worker-protocol-impl.hh"
#include "lix/libstore/derived-path.hh"
#include "lix/libstore/build-result.hh"
@@ -283,4 +284,36 @@ VERSIONED_CHARACTERIZATION_TEST(
},
}))
VERSIONED_CHARACTERIZATION_TEST(
WorkerProtoTest,
substitutablePathInfos,
"substitutable-path-infos",
defaultVersion,
(SubstitutablePathInfos{
{StorePath{
"g1w7hyyyy1w7hy3qg1w7hy3qgqqqqy3q-foo",
},
SubstitutablePathInfo{
std::nullopt,
{},
123456789,
987654321,
}},
{StorePath{
"g1w7hyyyy1w7hy3qg1w7hy3qgqqqqy3q-bar",
},
SubstitutablePathInfo{
StorePath{
"g1w7hyyyy1w7hy3qg1w7hy3qgqqqqy3q-fox",
},
{
StorePath{
"g1w7hyyyy1w7hy3qg1w7hy3qgqqqqy3q-other",
},
},
987654321,
123456789,
}},
})
)
}