clusterlin: add support for loading existing linearization (feature)
This commit is contained in:
1 parent
da48ed9f34
commit
6a8fa821b8
2 files changed
+46
-3
No files matched your search
+26
-1
@@ -777,6 +777,15 @@ public:
|
|||||||
* - Do a downwards merge of B, if possible. If so, repeat the same with the merged result.
|
* - Do a downwards merge of B, if possible. If so, repeat the same with the merged result.
|
||||||
* - Output the chunks from high to low feerate, each internally sorted topologically.
|
* - Output the chunks from high to low feerate, each internally sorted topologically.
|
||||||
*
|
*
|
||||||
|
* Instead of performing merges arbitrarily to make the initial state topological, it is possible
|
||||||
|
* to do so guided by an existing linearization. This has the advantage that the state's would-be
|
||||||
|
* output linearization is immediately as good as the existing linearization it was based on:
|
||||||
|
* - Start with all dependencies inactive.
|
||||||
|
* - For each transaction t in the existing linearization:
|
||||||
|
* - Find the chunk C that transaction is in (which will be singleton).
|
||||||
|
* - Do an upwards merge of C, if possible. If so, repeat the same with the merged result.
|
||||||
|
* No downwards merges are needed in this case.
|
||||||
|
*
|
||||||
* What remains to be specified are a number of heuristics:
|
* What remains to be specified are a number of heuristics:
|
||||||
*
|
*
|
||||||
* - How to decide which chunks to merge:
|
* - How to decide which chunks to merge:
|
||||||
@@ -1124,7 +1133,23 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Make state topological. Can be called after constructing. */
|
/** Load an existing linearization. Must be called immediately after constructor. The result is
|
||||||
|
* topological if the linearization is valid. Otherwise, MakeTopological still needs to be
|
||||||
|
* called. */
|
||||||
|
void LoadLinearization(std::span<const DepGraphIndex> old_linearization) noexcept
|
||||||
|
{
|
||||||
|
// Add transactions one by one, in order of existing linearization.
|
||||||
|
for (DepGraphIndex tx : old_linearization) {
|
||||||
|
auto chunk_rep = m_tx_data[tx].chunk_rep;
|
||||||
|
// Merge the chunk upwards, as long as merging succeeds.
|
||||||
|
while (true) {
|
||||||
|
chunk_rep = MergeStep<false>(chunk_rep);
|
||||||
|
if (chunk_rep == TxIdx(-1)) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Make state topological. Can be called after constructing, or after LoadLinearization. */
|
||||||
void MakeTopological() noexcept
|
void MakeTopological() noexcept
|
||||||
{
|
{
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|||||||
@@ -1190,6 +1190,10 @@ FUZZ_TARGET(clusterlin_sfl)
|
|||||||
InsecureRandomContext rng(rng_seed);
|
InsecureRandomContext rng(rng_seed);
|
||||||
/** Whether to make the depgraph connected. */
|
/** Whether to make the depgraph connected. */
|
||||||
const bool make_connected = flags & 1;
|
const bool make_connected = flags & 1;
|
||||||
|
/** Whether to load some input linearization into the state. */
|
||||||
|
const bool load_linearization = flags & 2;
|
||||||
|
/** Whether that input linearization is topological. */
|
||||||
|
const bool load_topological = load_linearization && (flags & 4);
|
||||||
|
|
||||||
// Initialize SFL state.
|
// Initialize SFL state.
|
||||||
if (make_connected) MakeConnected(depgraph);
|
if (make_connected) MakeConnected(depgraph);
|
||||||
@@ -1222,8 +1226,22 @@ FUZZ_TARGET(clusterlin_sfl)
|
|||||||
last_diagram = std::move(diagram);
|
last_diagram = std::move(diagram);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Make SFL state topological.
|
if (load_linearization) {
|
||||||
sfl.MakeTopological();
|
auto input_lin = ReadLinearization(depgraph, reader, load_topological);
|
||||||
|
sfl.LoadLinearization(input_lin);
|
||||||
|
if (load_topological) {
|
||||||
|
// The diagram of the loaded linearization forms an initial lower bound on future
|
||||||
|
// diagrams.
|
||||||
|
last_diagram = ChunkLinearization(depgraph, input_lin);
|
||||||
|
} else {
|
||||||
|
// The input linearization may have been non-topological, so invoke MakeTopological to
|
||||||
|
// fix it still.
|
||||||
|
sfl.MakeTopological();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Invoke MakeTopological to create an initial from-scratch topological state.
|
||||||
|
sfl.MakeTopological();
|
||||||
|
}
|
||||||
|
|
||||||
// Loop until optimal.
|
// Loop until optimal.
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|||||||
Reference in new issue
Block a user