/// <summary> /// Mounts the bucket. Mount is necessary before using a bucket to ensure the existence of tables and indexes. /// </summary> public async Task MountAsync(CancellationToken cancelToken = default) { if (this.Mounted) { return; } var filesTableResult = await EnsureTable(this.fileTableName, cancelToken) .ConfigureAwait(false); if (filesTableResult.TablesCreated == 1) { //index the file paths of completed files and status ReqlFunction1 pathIx = row => { return(R.Array(row[FileInfo.StatusJsonName], row[FileInfo.FileNameJsonName], row[FileInfo.FinishedDateJsonName])); }; await CreateIndex(this.fileTableName, this.fileIndex, pathIx, cancelToken) .ConfigureAwait(false); //prefix IX ReqlFunction1 prefixIx = doc => { //return r.array(doc[FileInfo.FileNameJsonName].split("/").slice(1, -1), doc[FileInfo.FinishedDateJsonName]); return(R.Branch(doc[FileInfo.StatusJsonName].Eq(Status.Completed), R.Array(doc[FileInfo.FileNameJsonName].Split("/").Slice(1, -1), doc[FileInfo.FinishedDateJsonName]), R.Error())); }; await CreateIndex(this.fileTableName, this.fileIndexPrefix, prefixIx, cancelToken) .ConfigureAwait(false); } // CHUNK TAABLE INDEXES var chunkTableResult = await EnsureTable(this.chunkTableName, cancelToken) .ConfigureAwait(false); if (chunkTableResult.TablesCreated == 1) { //Index the chunks and their parent [fileid, n]. ReqlFunction1 chunkIx = row => { return(R.Array(row[Chunk.FilesIdJsonName], row[Chunk.NumJsonName])); }; await CreateIndex(this.chunkTableName, this.chunkIndexName, chunkIx, cancelToken) .ConfigureAwait(false); } this.Mounted = true; }