Пример #1
0
        private void Setup(long size, LogSettings logSettings, TestUtils.DeviceType deviceType)
        {
            string filename = path + TestContext.CurrentContext.Test.Name + deviceType.ToString() + ".log";

            log = TestUtils.CreateTestDevice(deviceType, filename);
            logSettings.LogDevice = log;
            fht         = new FasterKV <KeyStruct, ValueStruct>(size, logSettings);
            fullSession = fht.For(new Functions()).NewSession <Functions>();
            uContext    = fullSession.GetUnsafeContext();
        }
Пример #2
0
 public void TearDown()
 {
     uContext?.Dispose();
     uContext = null;
     fullSession?.Dispose();
     fullSession = null;
     fht?.Dispose();
     fht = null;
     log?.Dispose();
     log = null;
     TestUtils.DeleteDirectory(path);
 }
Пример #3
0
        private Status ExecuteGet(ref KeyEnvelope keyEnvelope, ref ValueEnvelope inputEnvelope, ref ValueEnvelope outputEnvelope)
        {
            Status status = KVSession.Read(ref keyEnvelope, ref inputEnvelope, ref outputEnvelope, UnsafeContext, GetSerialNum());

            if (status == Status.PENDING)
            {
                KVSession.CompletePending(true, true);
                status = UnsafeContext.Consume(out outputEnvelope);
            }

            return(status);
        }
Пример #4
0
        void Prepare(out SimpleFunctions f,
                     out ClientSession <AdId, NumClicks, NumClicks, NumClicks, Empty, SimpleFunctions> s1,
                     out UnsafeContext <AdId, NumClicks, NumClicks, NumClicks, Empty, SimpleFunctions> uc1,
                     out ThreadSession <AdId, NumClicks, NumClicks, NumClicks, Empty, SimpleFunctions> s2,
                     long toVersion = -1)
        {
            f = new SimpleFunctions();

            // We should be in REST, 1
            Assert.IsTrue(SystemState.Equal(SystemState.Make(Phase.REST, 1), fht1.SystemState));

            // Take index checkpoint for recovery purposes
            fht1.TryInitiateIndexCheckpoint(out _);
            fht1.CompleteCheckpointAsync().AsTask().GetAwaiter().GetResult();

            // Index checkpoint does not update version, so
            // we should still be in REST, 1
            Assert.IsTrue(SystemState.Equal(SystemState.Make(Phase.REST, 1), fht1.SystemState));

            NumClicks value;

            s1 = fht1.For(f).NewSession <SimpleFunctions>("foo");

            for (int key = 0; key < numOps; key++)
            {
                value.numClicks = key;
                s1.Upsert(ref inputArray[key], ref value, Empty.Default, key);
            }

            // Ensure state machine needs no I/O wait during WAIT_FLUSH
            fht1.Log.ShiftReadOnlyAddress(fht1.Log.TailAddress, true);

            // Create unsafe context and hold epoch to prepare for manual state machine driver
            uc1 = s1.GetUnsafeContext();
            uc1.ResumeThread();

            // Start session s2 on another thread for testing
            s2 = fht1.For(f).CreateThreadSession(f);

            // We should be in REST, 1
            Assert.IsTrue(SystemState.Equal(SystemState.Make(Phase.REST, 1), fht1.SystemState));

            fht1.TryInitiateHybridLogCheckpoint(out _, CheckpointType.FoldOver, targetVersion: toVersion);

            // We should be in PREPARE, 1
            Assert.IsTrue(SystemState.Equal(SystemState.Make(Phase.PREPARE, 1), fht1.SystemState));
        }
Пример #5
0
        private void ServeRemove(Job job)
        {
            KeyEnvelope   keyEnvelope    = new KeyEnvelope(job.Key);
            ValueEnvelope outputEnvelope = default;

            Status status = Status.ERROR;

            try
            {
                status = KVSession.Delete(ref keyEnvelope, UnsafeContext, GetSerialNum());
                if (status == Status.PENDING)
                {
                    KVSession.CompletePending(true, true);
                    status = UnsafeContext.Consume(out outputEnvelope);
                }
            }
            catch (Exception e)
            {
                job.Complete(e);
            }

            switch (status)
            {
            case Status.ERROR:
                job.Complete(new Exception($"read error => {JsonSerializer.Serialize(job.Key)}"));
                break;

            case Status.NOTFOUND:
                job.Complete(false);
                break;

            case Status.OK:
                job.Complete(true, default);
                break;
            }
        }