예제 #1
0
        public void LargeObjectTest1()
        {
            log    = FasterFactory.CreateLogDevice(TestContext.CurrentContext.TestDirectory + "\\hlog", deleteOnClose: true);
            objlog = FasterFactory.CreateObjectLogDevice(TestContext.CurrentContext.TestDirectory + "\\hlog", deleteOnClose: true);

            Directory.CreateDirectory(TestContext.CurrentContext.TestDirectory + "\\checkpoints");

            fht1 = FasterFactory.Create
                   <MyKey, MyLargeValue, MyInput, MyLargeOutput, MyContext, MyLargeFunctions>
                       (indexSizeBuckets: 128, functions: new MyLargeFunctions(),
                       logSettings: new LogSettings {
                LogDevice = log, ObjectLogDevice = objlog, MutableFraction = 0.1, MemorySizeBits = 29
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointDir = TestContext.CurrentContext.TestDirectory + "\\checkpoints", CheckPointType = CheckpointType.Snapshot
            }
                       );

            fht2 = FasterFactory.Create
                   <MyKey, MyLargeValue, MyInput, MyLargeOutput, MyContext, MyLargeFunctions>
                       (indexSizeBuckets: 128, functions: new MyLargeFunctions(),
                       logSettings: new LogSettings {
                LogDevice = log, ObjectLogDevice = objlog, MutableFraction = 0.1, MemorySizeBits = 29
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointDir = TestContext.CurrentContext.TestDirectory + "\\checkpoints", CheckPointType = CheckpointType.Snapshot
            }
                       );


            int maxSize = 1000;
            int numOps  = 5000;

            //var value = new MyLargeValue(size);

            fht1.StartSession();
            Random r = new Random(33);

            for (int key = 0; key < numOps; key++)
            {
                var value = new MyLargeValue(1 + r.Next(maxSize));
                fht1.Upsert(new MyKey {
                    key = key
                }, value, null, 0);
            }
            fht1.TakeFullCheckpoint(out Guid token);
            fht1.CompleteCheckpoint(true);
            fht1.StopSession();
            fht1.Dispose();

            MyLargeOutput output = new MyLargeOutput();

            fht2.Recover(token);
            fht2.StartSession();
            for (int key = 0; key < numOps; key++)
            {
                var status = fht2.Read(new MyKey {
                    key = key
                }, new MyInput(), ref output, null, 0);

                if (status == Status.PENDING)
                {
                    fht2.CompletePending(true);
                }
                else
                {
                    for (int i = 0; i < output.value.value.Length; i++)
                    {
                        Assert.IsTrue(output.value.value[i] == (byte)(output.value.value.Length + i));
                    }
                }
            }
            fht2.StopSession();
            fht2.Dispose();

            log.Close();
            objlog.Close();
            new DirectoryInfo(TestContext.CurrentContext.TestDirectory + "\\checkpoints").Delete(true);
        }
예제 #2
0
        public unsafe void Populate()
        {
            // Prepare the dataset
            var inputArray = new Tuple <AdId, Input> [numOps];

            for (int i = 0; i < numOps; i++)
            {
                inputArray[i] = new Tuple <AdId, Input>
                                    (new AdId {
                    adId = i % numUniqueKeys
                }, new Input {
                    numClicks = 1
                });
            }

            // Register thread with FASTER
            fht.StartSession();

            // Prpcess the batch of input data
            bool first = true;

            for (int i = 0; i < numOps; i++)
            {
                fht.RMW(inputArray[i].Item1, inputArray[i].Item2, default(Empty), i);

                if ((i + 1) % checkpointInterval == 0)
                {
                    if (first)
                    {
                        while (!fht.TakeFullCheckpoint(out token))
                        {
                            fht.Refresh();
                        }
                    }
                    else
                    {
                        while (!fht.TakeFullCheckpoint(out Guid nextToken))
                        {
                            fht.Refresh();
                        }
                    }

                    fht.CompleteCheckpoint(true);

                    first = false;
                }

                if (i % completePendingInterval == 0)
                {
                    fht.CompletePending(false);
                }
                else if (i % refreshInterval == 0)
                {
                    fht.Refresh();
                }
            }


            // Make sure operations are completed
            fht.CompletePending(true);

            // Deregister thread from FASTER
            fht.StopSession();
        }