mirror of
https://github.com/nestriness/cdc-file-transfer.git
synced 2026-01-30 14:45:37 +02:00
Merge dynamic manifest updates to Github (#7)
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.
This commit is contained in:
@@ -12,11 +12,18 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Bazel does not honor copts for test targets, so we need to define
|
||||
// USE_MOCK_LIBFUSE in the test code itself *before* including cdc_fuse_fs.h.
|
||||
#ifndef USE_MOCK_LIBFUSE
|
||||
#define USE_MOCK_LIBFUSE = 1
|
||||
#endif
|
||||
|
||||
#include "cdc_fuse_fs/cdc_fuse_fs.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "cdc_fuse_fs/mock_config_stream_client.h"
|
||||
#include "cdc_fuse_fs/mock_libfuse.h"
|
||||
#include "common/log.h"
|
||||
#include "common/path.h"
|
||||
@@ -91,6 +98,7 @@ class CdcFuseFsTest : public ::testing::Test {
|
||||
CdcFuseFsTest() : builder_(&cache_) {
|
||||
cdc_fuse_fs::Initialize(0, nullptr).IgnoreError();
|
||||
Log::Initialize(std::make_unique<FuseLog>(LogLevel::kInfo));
|
||||
cdc_fuse_fs::SetConfigClient(std::make_unique<MockConfigStreamClient>());
|
||||
}
|
||||
~CdcFuseFsTest() {
|
||||
Log::Shutdown();
|
||||
@@ -157,17 +165,26 @@ class CdcFuseFsTest : public ::testing::Test {
|
||||
ExpectAccessError(R_OK | W_OK | X_OK, 0 /*error*/);
|
||||
}
|
||||
|
||||
// Wipes chunks for |kFile1Name| to simulate an intermediate manifest, i.e.
|
||||
// the manifest that contains all assets, but misses file chunks.
|
||||
// Wipes chunks for |kFile1Name| and assets for |kSubDirName| to simulate an
|
||||
// intermediate manifest, i.e. the manifest for which some files and
|
||||
// directories are not processed yet.
|
||||
// Returns the intermediate manifest id.
|
||||
ContentIdProto CreateIntermediateManifestId() {
|
||||
ManifestProto manifest;
|
||||
EXPECT_OK(cache_.GetProto(manifest_id_, &manifest));
|
||||
EXPECT_GT(manifest.root_dir().dir_assets_size(), 0);
|
||||
if (manifest.root_dir().dir_assets_size() == 0) return ContentIdProto();
|
||||
|
||||
AssetProto* file1 = manifest.mutable_root_dir()->mutable_dir_assets(0);
|
||||
EXPECT_EQ(file1->name(), kFile1Name);
|
||||
file1->clear_file_chunks();
|
||||
file1->set_in_progress(true);
|
||||
|
||||
AssetProto* subdir = manifest.mutable_root_dir()->mutable_dir_assets(1);
|
||||
EXPECT_EQ(subdir->name(), kSubdirName);
|
||||
subdir->clear_dir_assets();
|
||||
subdir->set_in_progress(true);
|
||||
|
||||
return cache_.AddProto(manifest);
|
||||
}
|
||||
|
||||
@@ -270,40 +287,59 @@ TEST_F(CdcFuseFsTest, OpenFailsWriteAccess) {
|
||||
EXPECT_EQ(fuse_.errors[0], EACCES);
|
||||
}
|
||||
|
||||
TEST_F(CdcFuseFsTest, OpenQueuedForIntermediateManifest) {
|
||||
TEST_F(CdcFuseFsTest, RequestsQueuedForIntermediateManifest) {
|
||||
ContentIdProto intermediate_manifest_id = CreateIntermediateManifestId();
|
||||
EXPECT_OK(cdc_fuse_fs::SetManifest(intermediate_manifest_id));
|
||||
fuse_file_info fi;
|
||||
auto cfg_client_ptr = std::make_unique<MockConfigStreamClient>();
|
||||
MockConfigStreamClient* cfg_client = cfg_client_ptr.get();
|
||||
cdc_fuse_fs::SetConfigClient(std::move(cfg_client_ptr));
|
||||
|
||||
// Opening file1 should be queued as it contains no chunks.
|
||||
// Opening file1 should be queued as it is marked as in-progress.
|
||||
CdcFuseLookup(req_, FUSE_ROOT_ID, kFile1Name);
|
||||
ASSERT_EQ(fuse_.entries.size(), 1);
|
||||
fuse_file_info fi;
|
||||
CdcFuseOpen(req_, fuse_.entries[0].ino, &fi);
|
||||
ASSERT_EQ(fuse_.open_files.size(), 0);
|
||||
EXPECT_EQ(fuse_.open_files.size(), 0);
|
||||
EXPECT_EQ(cfg_client->ReleasePrioritizedAssets(),
|
||||
std::vector<std::string>({kFile1Name}));
|
||||
|
||||
// Opening subdir should be queued as it is marked as in-progress.
|
||||
CdcFuseLookup(req_, FUSE_ROOT_ID, kSubdirName);
|
||||
ASSERT_EQ(fuse_.entries.size(), 2);
|
||||
CdcFuseOpenDir(req_, fuse_.entries[1].ino, &fi);
|
||||
EXPECT_EQ(fuse_.open_files.size(), 0);
|
||||
EXPECT_EQ(cfg_client->ReleasePrioritizedAssets(),
|
||||
std::vector<std::string>({kSubdirName}));
|
||||
|
||||
// Setting the final manifest should fulfill queued open requests.
|
||||
EXPECT_OK(cdc_fuse_fs::SetManifest(manifest_id_));
|
||||
ASSERT_EQ(fuse_.open_files.size(), 1);
|
||||
EXPECT_EQ(fuse_.open_files.size(), 2);
|
||||
}
|
||||
|
||||
TEST_F(CdcFuseFsTest, OpenQueuedRequestsRequeue) {
|
||||
TEST_F(CdcFuseFsTest, QueuedRequestsRequeue) {
|
||||
ContentIdProto intermediate_manifest_id = CreateIntermediateManifestId();
|
||||
EXPECT_OK(cdc_fuse_fs::SetManifest(intermediate_manifest_id));
|
||||
fuse_file_info fi;
|
||||
|
||||
// Opening file1 should be queued as it contains no chunks.
|
||||
// Opening file1 should be queued as it is marked as in-progress
|
||||
CdcFuseLookup(req_, FUSE_ROOT_ID, kFile1Name);
|
||||
ASSERT_EQ(fuse_.entries.size(), 1);
|
||||
fuse_file_info fi;
|
||||
CdcFuseOpen(req_, fuse_.entries[0].ino, &fi);
|
||||
ASSERT_EQ(fuse_.open_files.size(), 0);
|
||||
|
||||
// Opening subdir should be queued as it is marked as in-progress.
|
||||
CdcFuseLookup(req_, FUSE_ROOT_ID, kSubdirName);
|
||||
ASSERT_EQ(fuse_.entries.size(), 2);
|
||||
CdcFuseOpenDir(req_, fuse_.entries[1].ino, &fi);
|
||||
EXPECT_EQ(fuse_.open_files.size(), 0);
|
||||
|
||||
// Setting the same incomplete manifest again should requeue the request.
|
||||
EXPECT_OK(cdc_fuse_fs::SetManifest(intermediate_manifest_id));
|
||||
ASSERT_EQ(fuse_.open_files.size(), 0);
|
||||
|
||||
// Setting the final manifest should fulfill queued open requests.
|
||||
EXPECT_OK(cdc_fuse_fs::SetManifest(manifest_id_));
|
||||
ASSERT_EQ(fuse_.open_files.size(), 1);
|
||||
ASSERT_EQ(fuse_.open_files.size(), 2);
|
||||
}
|
||||
|
||||
TEST_F(CdcFuseFsTest, ReadSucceeds) {
|
||||
|
||||
Reference in New Issue
Block a user