コード例 #1
0
 public void Test_Cannot_Create_Or_Partition_Subspace_With_Slice_Nil()
 {
     Assert.That(() => new FdbSubspace(Slice.Nil), Throws.ArgumentException);
     Assert.That(() => FdbSubspace.Create(Slice.Nil), Throws.ArgumentException);
     Assert.That(() => FdbSubspace.Empty[Slice.Nil], Throws.ArgumentException);
     Assert.That(() => FdbSubspace.Create(FdbKey.Directory)[Slice.Nil], Throws.ArgumentException);
 }
コード例 #2
0
 public void Test_Cannot_Create_Or_Partition_Subspace_With_Null_Tuple()
 {
     Assert.That(() => FdbSubspace.Create(default(IFdbTuple)), Throws.InstanceOf <ArgumentNullException>());
     //FIXME: typed subspaces refactoring !
     //Assert.That(() => FdbSubspace.Empty.Partition[default(IFdbTuple)], Throws.InstanceOf<ArgumentNullException>());
     //Assert.That(() => FdbSubspace.Create(FdbKey.Directory).Partition[default(IFdbTuple)], Throws.InstanceOf<ArgumentNullException>());
 }
コード例 #3
0
 public void Test_Cannot_Create_Or_Partition_Subspace_With_Slice_Nil()
 {
     Assert.That(() => new FdbSubspace(Slice.Nil), Throws.ArgumentException);
     Assert.That(() => FdbSubspace.Create(Slice.Nil), Throws.ArgumentException);
     //FIXME: typed subspaces refactoring !
     //Assert.That(() => FdbSubspace.Empty.Partition[Slice.Nil], Throws.ArgumentException);
     //Assert.That(() => FdbSubspace.Create(FdbKey.Directory).Partition[Slice.Nil], Throws.ArgumentException);
 }
コード例 #4
0
        private async Task Scenario6(IFdbTransaction tr)
        {
            var location = FdbSubspace.Create(Slice.FromAscii("TEST"));

            tr.AtomicAdd(location.Pack("ATOMIC"), Slice.FromFixed32(0x55555555));

            var x = await tr.GetAsync(location.Pack("ATOMIC"));

            Console.WriteLine(x.ToInt32().ToString("x"));
        }
コード例 #5
0
        private Task Scenario4(IFdbTransaction tr)
        {
            var location = FdbSubspace.Create(Slice.FromAscii("TEST"));

            //tr.Set(location.Key, Slice.FromString("NARF"));
            //tr.AtomicAdd(location.Key, Slice.FromFixedU32(1));
            tr.AtomicAnd(location.Key, Slice.FromFixedU32(7));
            tr.AtomicXor(location.Key, Slice.FromFixedU32(3));
            tr.AtomicXor(location.Key, Slice.FromFixedU32(15));
            return(Task.FromResult <object>(null));
        }
コード例 #6
0
        private Task Scenario3(IFdbTransaction tr)
        {
            var location = FdbSubspace.Create(Slice.FromAscii("TEST"));

            tr.Set(location.Key + (byte)'a', Slice.FromAscii("A"));
            tr.AtomicAdd(location.Key + (byte)'k', Slice.FromFixed32(1));
            tr.Set(location.Key + (byte)'z', Slice.FromAscii("C"));
            tr.ClearRange(location.Key + (byte)'a', location.Key + (byte)'k');
            tr.ClearRange(location.Key + (byte)'k', location.Key + (byte)'z');
            return(Task.FromResult <object>(null));
        }
コード例 #7
0
        private Task Scenario2(IFdbTransaction tr)
        {
            var location = FdbSubspace.Create(Slice.FromAscii("TEST"));

            tr.ClearRange(FdbKeyRange.StartsWith(location.Key));
            for (int i = 0; i < 10; i++)
            {
                tr.Set(location.Pack(i), Slice.FromString("value of " + i));
            }
            return(Task.FromResult <object>(null));
        }
コード例 #8
0
        private async Task Scenario5(IFdbTransaction tr)
        {
            var location = FdbSubspace.Create(Slice.FromAscii("TEST"));

            //tr.Set(location.Pack(42), Slice.FromString("42"));
            //tr.Set(location.Pack(50), Slice.FromString("50"));
            //tr.Set(location.Pack(60), Slice.FromString("60"));

            var x = await tr.GetKeyAsync(FdbKeySelector.LastLessThan(location.Pack(49)));

            Console.WriteLine(x);

            tr.Set(location.Pack("FOO"), Slice.FromString("BAR"));
        }
コード例 #9
0
        public void Test_Subspace_Copy_Does_Not_Share_Key_Buffer()
        {
            var original = FdbSubspace.Create(Slice.FromString("Hello"));
            var copy     = FdbSubspace.Copy(original);

            Assert.That(copy, Is.Not.Null);
            Assert.That(copy, Is.Not.SameAs(original), "Copy should be a new instance");
            Assert.That(copy.Key, Is.EqualTo(original.Key), "Key should be equal");
            Assert.That(copy.Key.Array, Is.Not.SameAs(original.Key.Array), "Key should be a copy of the original");

            Assert.That(copy, Is.EqualTo(original), "Copy and original should be considered equal");
            Assert.That(copy.ToString(), Is.EqualTo(original.ToString()), "Copy and original should have the same string representation");
            Assert.That(copy.GetHashCode(), Is.EqualTo(original.GetHashCode()), "Copy and original should have the same hashcode");
        }
コード例 #10
0
        public async Task Test_Can_Open_Database_With_Non_Empty_GlobalSpace()
        {
            // using a tuple prefix
            using (var db = await Fdb.OpenAsync(null, "DB", FdbSubspace.Create(STuple.EncodeKey("test")), false, this.Cancellation))
            {
                Assert.That(db, Is.Not.Null);
                Assert.That(db.GlobalSpace, Is.Not.Null);
                Assert.That(db.GlobalSpace.Key.ToString(), Is.EqualTo("<02>test<00>"));

                var subspace = db.Partition.ByKey("hello");
                Assert.That(subspace.Key.ToString(), Is.EqualTo("<02>test<00><02>hello<00>"));

                // keys inside the global space are valid
                Assert.That(db.IsKeyValid(STuple.EncodeKey("test", 123)), Is.True);

                // keys outside the global space are invalid
                Assert.That(db.IsKeyValid(Slice.Create(new byte[] { 42 })), Is.False);
            }

            // using a random binary prefix
            using (var db = await Fdb.OpenAsync(null, "DB", new FdbSubspace(Slice.Create(new byte[] { 42, 255, 0, 90 })), false, this.Cancellation))
            {
                Assert.That(db, Is.Not.Null);
                Assert.That(db.GlobalSpace, Is.Not.Null);
                Assert.That(db.GlobalSpace.Key.ToString(), Is.EqualTo("*<FF><00>Z"));

                var subspace = db.Partition.ByKey("hello");
                Assert.That(subspace.Key.ToString(), Is.EqualTo("*<FF><00>Z<02>hello<00>"));

                // keys inside the global space are valid
                Assert.That(db.IsKeyValid(Slice.Unescape("*<FF><00>Z123")), Is.True);

                // keys outside the global space are invalid
                Assert.That(db.IsKeyValid(Slice.Create(new byte[] { 123 })), Is.False);
                Assert.That(db.IsKeyValid(Slice.Unescape("*<FF>")), Is.False);
            }
        }
コード例 #11
0
        private Task <FdbDatabase> OpenDatabaseAsync()
        {
            var globalSpace = FdbSubspace.Create(FdbTuple.Create(PREFIX));

            return(Fdb.OpenAsync(CLUSTER_FILE, DB_NAME, globalSpace));
        }
コード例 #12
0
 internal FdbDirectoryPartition(IFdbTuple location, IFdbTuple relativeLocation, Slice prefix, FdbDirectoryLayer directoryLayer)
     : base(location, relativeLocation, prefix, new FdbDirectoryLayer(FdbSubspace.Create(prefix + FdbKey.Directory), FdbSubspace.Create(prefix), location), LayerId)
 {
     m_parentDirectoryLayer = directoryLayer;
 }
コード例 #13
0
        private static async Task MainAsync(CancellationToken ct)
        {
            // change the path to the native lib if not default
            if (NATIVE_PATH != null)
            {
                Fdb.Options.SetNativeLibPath(NATIVE_PATH);
            }

            // uncomment this to enable network thread tracing
            // FdbCore.TracePath = Path.Combine(Path.GetTempPath(), "fdb");

            int apiVersion = Fdb.GetMaxApiVersion();

            Console.WriteLine("Max API Version: " + apiVersion);

            try
            {
                Console.WriteLine("Starting network thread...");
                Fdb.Start();                 // this will select API version 21
                Console.WriteLine("> Up and running");

                Console.WriteLine("Connecting to local cluster...");
                using (var cluster = await Fdb.CreateClusterAsync(CLUSTER_FILE, ct))
                {
                    Console.WriteLine("> Connected!");

                    Console.WriteLine("Opening database 'DB'...");
                    using (var db = await cluster.OpenDatabaseAsync(DB_NAME, FdbSubspace.Create(STuple.EncodeKey(SUBSPACE)), false, ct))
                    {
                        Console.WriteLine("> Connected to db '{0}'", db.Name);

                        // get coordinators
                        var cf = await Fdb.System.GetCoordinatorsAsync(db, ct);

                        Console.WriteLine("Coordinators: " + cf.ToString());

                        // clear everything
                        using (var tr = db.BeginTransaction(ct))
                        {
                            Console.WriteLine("Clearing subspace " + db.GlobalSpace + " ...");
                            tr.ClearRange(db.GlobalSpace);
                            await tr.CommitAsync();

                            Console.WriteLine("> Database cleared");
                        }

                        Console.WriteLine("----------");

                        await TestSimpleTransactionAsync(db, ct);

                        Console.WriteLine("----------");

                        await BenchInsertSmallKeysAsync(db, N, 16, ct);                         // some guid
                        await BenchInsertSmallKeysAsync(db, N, 60 * 4, ct);                     // one Int32 per minutes, over an hour
                        await BenchInsertSmallKeysAsync(db, N, 512, ct);                        // small JSON payload

                        ////await BenchInsertSmallKeysAsync(db, N, 4096, ct); // typical small cunk size
                        ////await BenchInsertSmallKeysAsync(db, N / 10, 65536, ct); // typical medium chunk size
                        //await BenchInsertSmallKeysAsync(db, 1, 100000, ct); // Maximum value size (as of beta 1)

                        ////// insert keys in parrallel
                        await BenchConcurrentInsert(db, 1, 100, 512, ct);
                        await BenchConcurrentInsert(db, 1, 1000, 512, ct);
                        await BenchConcurrentInsert(db, 1, 10000, 512, ct);

                        await BenchConcurrentInsert(db, 1, N, 16, ct);
                        await BenchConcurrentInsert(db, 2, N, 16, ct);
                        await BenchConcurrentInsert(db, 4, N, 16, ct);
                        await BenchConcurrentInsert(db, 8, N, 16, ct);
                        await BenchConcurrentInsert(db, 16, N, 16, ct);

                        //await BenchSerialWriteAsync(db, N, ct);
                        //await BenchSerialReadAsync(db, N, ct);
                        //await BenchConcurrentReadAsync(db, N, ct);

                        //await BenchClearAsync(db, N, ct);

                        await BenchUpdateSameKeyLotsOfTimesAsync(db, 1000, ct);

                        await BenchUpdateLotsOfKeysAsync(db, 1000, ct);

                        await BenchBulkInsertThenBulkReadAsync(db, 100 * 1000, 50, 128, ct);
                        await BenchBulkInsertThenBulkReadAsync(db, 100 * 1000, 128, 50, ct);

                        ////await BenchBulkInsertThenBulkReadAsync(db, 1 * 1000 * 1000, 50, 128, ct);

                        await BenchMergeSortAsync(db, 100, 3, 20, ct);
                        await BenchMergeSortAsync(db, 1000, 10, 100, ct);
                        await BenchMergeSortAsync(db, 100, 100, 100, ct);
                        await BenchMergeSortAsync(db, 100, 1000, 100, ct);

                        Console.WriteLine("time to say goodbye...");
                    }
                }
            }
            finally
            {
                Console.WriteLine("### DONE ###");
                Fdb.Stop();
            }
#if DEBUG
            Console.ReadLine();
#endif
        }
コード例 #14
0
 public void Test_Cannot_Create_Or_Partition_Subspace_With_Null_Tuple()
 {
     Assert.That(() => new FdbSubspace(default(IFdbTuple)), Throws.InstanceOf <ArgumentNullException>());
     Assert.That(() => FdbSubspace.Empty[default(IFdbTuple)], Throws.InstanceOf <ArgumentNullException>());
     Assert.That(() => FdbSubspace.Create(FdbKey.Directory)[default(IFdbTuple)], Throws.InstanceOf <ArgumentNullException>());
 }