Ejemplo n.º 1
0
        public BucketTest()
        {
            Log.TruncateBinaryTypes = true;

            fileTable = R.Db(DbName).Table("fs_files");
            chunkTable = R.Db(DbName).Table("fs_chunk");
            db = R.Db(DbName);
            var opts = new BucketConfig();
            chunkIndex = opts.ChunkIndex;
            fileIndexPath = opts.FileIndex;
            fileTableName = "fs_files";
            chunkTableName = "fs_chunks";
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an UploadStream to ReGrid.
        /// </summary>
        /// <param name="conn">RethinkDB Connection or ConnectonPool.</param>
        /// <param name="filesInfoId">The ID of the FileInfo in the database.</param>
        /// <param name="fileInfo">An incomplete FileInfo that exists in the database waiting to be finalized.</param>
        /// <param name="fileTable">An already namespaced Table term for FileInfo.</param>
        /// <param name="chunkTable">An already namespaced Table term for Chunk</param>
        /// <param name="options">Upload options</param>
        internal UploadStream(IConnection conn, Guid filesInfoId, FileInfo fileInfo, Table fileTable, Table chunkTable, UploadOptions options) : base(fileInfo)
        {
            this.conn = conn;
            this.filesInfoId = filesInfoId;
            this.fileTable = fileTable;
            this.chunkTable = chunkTable;
            this.chunkInsertOpts = options.ChunkInsertOptions;
            this.chunkSizeBytes = options.ChunkSizeBytes;

            this.batchSize = options.BatchSize;

            this.batch = new List<byte[]>();

            sha256 = new IncrementalSHA256();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a new bucket.
        /// </summary>
        /// <param name="conn">A <see cref="Connection"/> or <see cref="ConnectionPool"/></param>
        /// <param name="databaseName">The database name to use. The database must exist.</param>
        /// <param name="bucketName">The bucket name to use.</param>
        /// <param name="config">Low level bucket configuration options.</param>
        public Bucket(IConnection conn, string databaseName, string bucketName = "fs", BucketConfig config = null)
        {
            this.conn = conn;

            this.databaseName = databaseName;
            this.db = R.Db(this.databaseName);

            config = config ?? new BucketConfig();

            this.tableCreateOpts = config.TableCreateOptions;

            this.fileTableName = $"{bucketName}_{config.FileTableName}";
            this.fileTable = this.db.Table(fileTableName);
            this.fileIndex = config.FileIndex;
            this.fileIndexPrefix = config.FileIndexPrefix;

            this.chunkTableName = $"{bucketName}_{config.ChunkTable}";
            this.chunkTable = this.db.Table(chunkTableName);
            this.chunkIndexName = config.ChunkIndex;
        }
 public RethinkDbQueryModelVisitor( Table table )
 {
     _table = table;
 }
 public TestRethinkQueryExecutor( Table table, IConnection connection, Action<ReqlAst> validate ) : base( table, connection )
 {
     this.validate = validate;
 }
Ejemplo n.º 6
0
/// <summary>
/// <para>Rebalances the shards of a table. When called on a database, all the tables in that database will be rebalanced.</para>
///</summary>
/// <example><para>Example: Rebalance a table.</para>
/// <code>&gt; r.table('superheroes').rebalance().run(conn, callback);
/// </code></example>
                    public Rebalance rebalance ( Table table )
                    {
                        Arguments arguments = new Arguments();
                        arguments.CoerceAndAdd(table);
                        return new Rebalance (arguments);
                    }
Ejemplo n.º 7
0
/// <summary>
/// <para>Reconfigure a table's sharding and replication.</para>
///</summary>
/// <example><para>Example: Reconfigure a table.</para>
/// <code>&gt; r.table('superheroes').reconfigure({shards: 2, replicas: 1}).run(conn, callback);
/// </code></example>
                    public Reconfigure reconfigure ( Table table )
                    {
                        Arguments arguments = new Arguments();
                        arguments.CoerceAndAdd(table);
                        return new Reconfigure (arguments);
                    }
Ejemplo n.º 8
0
/// <summary>
/// <para>Wait for a table or all the tables in a database to be ready. A table may be temporarily unavailable after creation, rebalancing or reconfiguring. The <code>wait</code> command blocks until the given table (or database) is fully up to date.</para>
///</summary>
/// <example><para>Example: Wait for a table to be ready.</para>
/// <code>&gt; r.table('superheroes').wait().run(conn, callback);
/// </code></example>
                    public Wait wait_ ( Table table )
                    {
                        Arguments arguments = new Arguments();
                        arguments.CoerceAndAdd(table);
                        return new Wait (arguments);
                    }
Ejemplo n.º 9
0
        public async Task<ReqlExpr> AsTableQueryAsync(RethinkDB rdb, Table table, string requesterId, string feedOwnerId, CancellationToken cancellationToken = default(CancellationToken))
        {
            // Build the base query.
            var query = await this.AsCountTableQueryAsync(rdb, table, requesterId, feedOwnerId, cancellationToken);

            // Apply the skip.
            if (this.skip.HasValue)
                query = query.Skip(this.skip.Value);

            // Apply the limit.
            if (this.limit.HasValue)
                query = query.Limit(this.limit.Value);

            return query;
        }
Ejemplo n.º 10
0
        public async Task<ReqlExpr> AsCountTableQueryAsync(RethinkDB rdb, Table table, string requesterId, string feedOwnerId, CancellationToken cancellationToken = default(CancellationToken))
        {
            // Make sure we have all the data we need.
            await this.resolveDependenciesRunner.RunOnce(cancellationToken);

            // Find the name of the index to use.
            var index = this.TableIndex();

            // Find the date boundary values.
            var lowerDateBound = this.boundaries?.TryGetValue(TentFeedRequestBoundaryType.Since)?.Date
                ?? this.boundaries?.TryGetValue(TentFeedRequestBoundaryType.Until)?.Date;
            var upperDateBound = this.boundaries?.TryGetValue(TentFeedRequestBoundaryType.Before)?.Date;

            // Filter by owner and date.
            var query = (ReqlExpr)table.Between(
                new object[] { feedOwnerId, lowerDateBound != null ? rdb.Expr(lowerDateBound) : rdb.Minval() },
                new object[] { feedOwnerId, upperDateBound != null ? rdb.Expr(upperDateBound) : rdb.Maxval() })[new
                {
                    index,
                    left_bound = "open",
                    right_bound = "open"
                }];

            // Set the order-by depending on the boundary type.
            query = query.OrderBy()[new { index = this.boundaries != null && this.boundaries.ContainsKey(TentFeedRequestBoundaryType.Since) ? (object)rdb.Asc(index) : (object)rdb.Desc(index) }];

            var filters = new List<Func<ReqlExpr, ReqlExpr>>();

            // Entities.
            if (this.specialEntities == TentFeedRequestSpecialEntities.Followings)
                filters.Add(r => r.G("is_from_following").Eq(true));
            else if (this.users != null && this.users.Any())
                filters.Add(r => rdb.BetterOr(this.users.Select(u => r.G("user").Eq(u.Id)).Cast<object>().ToArray()));

            // Post type filter.
            if (this.types != null && this.types.Any())
            {
                // Condition on a single type.
                var typeCondition = new Func<ReqlExpr, ITentPostType, ReqlExpr>((r, type) => type.WildCard
                    ? (ReqlExpr)r.G("type").Match($"^{Regex.Escape(type.Type)}#")
                    : r.G("type").Eq(type.ToString()));

                // Combine the type conditions as part of an OR expression.
                filters.Add(r => rdb.BetterOr(this.types.Select(type => typeCondition(r, type)).Cast<object>().ToArray()));
            }

            // Condition on a single mention.
            var mentionCondition = new Func<ReqlExpr, ITentRequestPost, ReqlExpr>((r, mention) => r.G("mentions")
                // Map each mention for the current row to a boolean.
                .Map(m => mention.Post == null
                    ? m.G("user").Eq(mention.User.Id)
                    : rdb.BetterAnd(m.G("user").Eq(mention.User.Id), m.G("post").Eq(mention.Post.Id)))
                // Reduce the resulting booleans to just one (any).
                .Reduce((b1, b2) => rdb.BetterOr(b1, b2))
                .Default_(false));

            // Mentions.
            if (this.mentions != null && this.mentions.Any())
            {
                // Combine the mention conditions, first by AND, then by OR.
                filters.Add(r => rdb.BetterAnd(this.mentions
                    .Select(andMentions =>
                        rdb.BetterOr(andMentions.Select(mention =>
                            mentionCondition(r, mention)).Cast<object>().ToArray()))
                    .Cast<object>().ToArray()));
            }

            // Not mentions.
            if (this.notMentions != null && this.notMentions.Any())
            {
                // Combine the not mention conditions, first by AND, then by OR.
                filters.Add(r => rdb.BetterAnd(this.notMentions
                    .Select(andNotMentions =>
                        rdb.BetterOr(andNotMentions.Select(notMention =>
                            mentionCondition(r, notMention).Not()).Cast<object>().ToArray()))
                    .Cast<object>().ToArray()));
            }

            // Permissions.
            if (requesterId != feedOwnerId)
            {
                filters.Add(r => rdb.BetterAnd(
                    r.G("user").Eq(feedOwnerId),
                    rdb.BetterOr(
                        r.G("permissions").G("public").Eq(true),
                        r.G("permissions").G("users").Contains(requesterId))));
            }

            // Apply all the filters as part of an AND expression.
            if (filters.Any())
                query = query.Filter(r => rdb.BetterAnd(filters.Select(f => f(r)).Cast<object>().ToArray()));

            return query;
        }