mirror of
https://github.com/nestriness/cdc-file-transfer.git
synced 2026-01-30 12:25:35 +02:00
This change introduces dynamic manifest updates to asset streaming. Asset streaming describes the directory to be streamed in a manifest, which is a proto definition of all content metadata. This information is sufficient to answer `stat` and `readdir` calls in the FUSE layer without additional round-trips to the workstation. When a directory is streamed for the first time, the corresponding manifest is created in two steps: 1. The directory is traversed recursively and the inode information of all contained files and directories is written to the manifest. 2. The content of all identified files is processed to generate each file's chunk list. This list is part of the definition of a file in the manifest. * The chunk boundaries are identified using our implementation of the FastCDC algorithm. * The hash of each chunk is calculated using the BLAKE3 hash function. * The length and hash of each chunk is appended to the file's chunk list. Prior to this change, when the user mounted a workstation directory on a client, the asset streaming server pushed an intermediate manifest to the gamelet as soon as step 1 was completed. At this point, the FUSE client started serving the virtual file system and was ready to answer `stat` and `readdir` calls. In case the FUSE client received any call that required file contents, such as `read`, it would block the caller until the server completed step 2 above and pushed the final manifest to the client. This works well for large directories (> 100GB) with a reasonable number of files (< 100k). But when dealing with millions of tiny files, creating the full manifest can take several minutes. With this change, we introduce dynamic manifest updates. When the FUSE layer receives an `open` or `readdir` request for a file or directory that is incomplete, it sends an RPC to the workstation about what information is missing from the manifest. The workstation identifies the corresponding file chunker or directory scanner tasks and moves them to the front of the queue. As soon as the task is completed, the workstation pushes an updated intermediate manifest to the client which now includes the information to serve the FUSE request. The queued FUSE request is resumed and returns the result to the caller. While this does not reduce the required time to build the final manifest, it splits up the work into smaller tasks. This allows us to interrupt the current work and prioritize those tasks which are required to handle an incoming request from the client. While this still takes a round-trip to the workstation plus the processing time for the task, an updated manifest is received within a few seconds, which is much better than blocking for several minutes. This latency is only visible when serving data while the manifest is still being created. The situation improves as the manifest creation on the workstation progresses. As soon as the final manifest is pushed, all metadata can be served directly without having to wait for pending tasks.
95 lines
3.2 KiB
C++
95 lines
3.2 KiB
C++
// Copyright 2022 Google LLC
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#include "manifest/pending_assets_queue.h"
|
|
|
|
#include "common/log.h"
|
|
#include "manifest/manifest_builder.h"
|
|
|
|
namespace cdc_ft {
|
|
|
|
PendingAssetsQueue::PendingAssetsQueue(absl::Duration min_processing_time)
|
|
: min_processing_time_(min_processing_time) {}
|
|
|
|
void PendingAssetsQueue::Add(PendingAsset pending) {
|
|
if (pending.deadline == absl::InfiniteFuture()) {
|
|
queue_.push_back(std::move(pending));
|
|
return;
|
|
}
|
|
|
|
// Pending assets with a deadline will be added at the end of other
|
|
// prioritized assets.
|
|
auto it =
|
|
std::find_if(queue_.begin(), queue_.end(), [](const PendingAsset& pa) {
|
|
return pa.deadline == absl::InfiniteFuture();
|
|
});
|
|
queue_.insert(it, std::move(pending));
|
|
}
|
|
|
|
bool PendingAssetsQueue::Dequeue(PendingAsset* pending, AcceptFunc accept) {
|
|
auto it = queue_.begin();
|
|
while (it != queue_.end() && accept && !accept(*it)) ++it;
|
|
if (it == queue_.end()) return false;
|
|
*pending = std::move(*it);
|
|
queue_.erase(it);
|
|
return true;
|
|
}
|
|
|
|
absl::Time PendingAssetsQueue::Prioritize(
|
|
const std::vector<PriorityAsset>& prio_assets,
|
|
ManifestBuilder* manifest_builder) {
|
|
absl::Time min_received = absl::InfiniteFuture();
|
|
|
|
for (const PriorityAsset& prio_asset : prio_assets) {
|
|
if (prio_asset.received < min_received) min_received = prio_asset.received;
|
|
|
|
// Check if this asset is still in progress.
|
|
absl::StatusOr<AssetBuilder> asset = manifest_builder->GetOrCreateAsset(
|
|
prio_asset.rel_file_path, AssetProto::UNKNOWN);
|
|
if (!asset.ok()) {
|
|
LOG_ERROR("Failed to prioritize asset '%s': %s", prio_asset.rel_file_path,
|
|
asset.status().ToString());
|
|
continue;
|
|
}
|
|
if (!asset->InProgress()) continue;
|
|
|
|
// Find the queued task for this asset.
|
|
auto prio_end = queue_.end();
|
|
for (auto it = queue_.begin(); it != queue_.end(); ++it) {
|
|
// Remember the first task that is not prioritized so that we can insert
|
|
// new prioritized tasks just before.
|
|
if (prio_end == queue_.end() && it->deadline == absl::InfiniteFuture()) {
|
|
prio_end = it;
|
|
}
|
|
|
|
if (it->relative_path == asset->RelativePath() &&
|
|
it->filename == asset->Name()) {
|
|
// If this asset is not yet prioritized, |prio_end| will be set
|
|
// accordingly and we move |*it| to the end of the prioritized tasks.
|
|
if (it->deadline == absl::InfiniteFuture()) {
|
|
it->deadline = prio_asset.received + min_processing_time_;
|
|
it->prioritized = true; // Expliciy prioritization.
|
|
queue_.insert(prio_end, std::move(*it));
|
|
queue_.erase(it);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return min_received + min_processing_time_;
|
|
}
|
|
|
|
} // namespace cdc_ft
|