예제 #1
0
 public void AddDeltaLog(DeltaLog log)
 {
     if (log is DeltaLogAddEdge)
     {
         this.isAddE = true;
     }
     else if (log is DeltaLogDropEdge)
     {
         this.isDropE = true;
         this.deltaProperties.Clear();
     }
     else if (log is DeltaLogUpdateEdgeProperties)
     {
         DeltaLogUpdateEdgeProperties deltaLog = log as DeltaLogUpdateEdgeProperties;
         foreach (Tuple <string, JValue> property in deltaLog.edgeProperties)
         {
             string name = property.Item1;
             this.deltaProperties[name] = new Tuple <EdgeDeltaType, JValue>(EdgeDeltaType.UpdateProperty, property.Item2);
         }
     }
     else if (log is DeltaLogDropEdgeProperty)
     {
         DeltaLogDropEdgeProperty deltaLog = log as DeltaLogDropEdgeProperty;
         string name = deltaLog.propertyName;
         this.deltaProperties[name] = new Tuple <EdgeDeltaType, JValue>(EdgeDeltaType.DropProperty, null);
     }
 }
예제 #2
0
        public void DeltaLogTest1([Values] TestUtils.DeviceType deviceType)
        {
            const int TotalCount = 200;
            string    filename   = $"{path}delta_{deviceType}.log";

            TestUtils.RecreateDirectory(path);

            device = TestUtils.CreateTestDevice(deviceType, filename);
            device.Initialize(-1);
            using DeltaLog deltaLog = new DeltaLog(device, 12, 0);
            Random r = new (20);
            int    i;

            SectorAlignedBufferPool bufferPool = new(1, (int)device.SectorSize);

            deltaLog.InitializeForWrites(bufferPool);
            for (i = 0; i < TotalCount; i++)
            {
                int  _len = 1 + r.Next(254);
                long address;
                while (true)
                {
                    deltaLog.Allocate(out int maxLen, out address);
                    if (_len <= maxLen)
                    {
                        break;
                    }
                    deltaLog.Seal(0);
                }
                for (int j = 0; j < _len; j++)
                {
                    unsafe { *(byte *)(address + j) = (byte)_len; }
                }
                deltaLog.Seal(_len, i % 2 == 0 ? DeltaLogEntryType.DELTA : DeltaLogEntryType.CHECKPOINT_METADATA);
            }
            deltaLog.FlushAsync().Wait();

            deltaLog.InitializeForReads();
            r = new (20);
            for (i = 0; deltaLog.GetNext(out long address, out int len, out var type); i++)
            {
                int _len = 1 + r.Next(254);
                Assert.AreEqual(i % 2 == 0 ? DeltaLogEntryType.DELTA : DeltaLogEntryType.CHECKPOINT_METADATA, type);
                Assert.AreEqual(len, _len);
                for (int j = 0; j < len; j++)
                {
                    unsafe { Assert.AreEqual((byte)_len, *(byte *)(address + j)); };
                }
            }
            Assert.AreEqual(TotalCount, i, $"i={i} and TotalCount={TotalCount}");
            bufferPool.Free();
        }
예제 #3
0
        internal void AddOrUpdateVertexDelta(VertexField vertexField, DeltaLog log)
        {
            string           vertexId = vertexField.VertexId;
            DeltaVertexField delta;

            if (vertexDelta.ContainsKey(vertexId))
            {
                delta = vertexDelta[vertexId];
            }
            else
            {
                delta = new DeltaVertexField(vertexField);
                vertexDelta.Add(vertexId, delta);
            }
            delta.AddDeltaLog(log);
        }
예제 #4
0
        public void AddDeltaLog(DeltaLog log)
        {
            if (log is DeltaLogAddVertex)
            {
                this.isAddV = true;
            }
            else if (log is DeltaLogDropVertex)
            {
                this.isDropV = true;
                this.deltaProperties.Clear();
            }
            else if (log is DeltaLogDropVertexSingleProperty)
            {
                DeltaLogDropVertexSingleProperty deltaLog = log as DeltaLogDropVertexSingleProperty;
                string name = deltaLog.propertyName;
                string id   = deltaLog.propertyId;

                if (!this.deltaProperties.ContainsKey(name))
                {
                    this.deltaProperties[name] = new Dictionary <string, Tuple <VertexDeltaType, JValue, Dictionary <string, Tuple <VertexDeltaType, JValue> > > >();
                }

                this.deltaProperties[name][id] = new Tuple <VertexDeltaType, JValue, Dictionary <string, Tuple <VertexDeltaType, JValue> > >(
                    VertexDeltaType.DropSingleProperty, null, null);
            }
            else if (log is DeltaLogDropVertexMetaProperty)
            {
                DeltaLogDropVertexMetaProperty deltaLog = log as DeltaLogDropVertexMetaProperty;
                string parentName = deltaLog.parentPropertyName;
                string parentId   = deltaLog.parentPropertyId;

                if (!this.deltaProperties.ContainsKey(parentName))
                {
                    this.deltaProperties[parentName] = new Dictionary <string, Tuple <VertexDeltaType, JValue, Dictionary <string, Tuple <VertexDeltaType, JValue> > > >();
                }

                if (this.deltaProperties[parentName].ContainsKey(parentId))
                {
                    Tuple <VertexDeltaType, JValue, Dictionary <string, Tuple <VertexDeltaType, JValue> > > singleProperty =
                        this.deltaProperties[parentName][parentId];

                    if (singleProperty.Item1 == VertexDeltaType.DropSingleProperty)
                    {
                        // maybe something wrong, drop a meta-property from a droped single-property
                        return;
                    }

                    Dictionary <string, Tuple <VertexDeltaType, JValue> > metaProperties = singleProperty.Item3;

                    if (metaProperties.ContainsKey(deltaLog.propertyName))
                    {
                        if (metaProperties[deltaLog.propertyName].Item1 == VertexDeltaType.UpdateMetaPropertiesOfSingleProperty)
                        {
                            metaProperties[deltaLog.propertyName] = new Tuple <VertexDeltaType, JValue>(VertexDeltaType.DropPropertyMetaProperty, null);
                        }
                        else if (metaProperties[deltaLog.propertyName].Item1 == VertexDeltaType.UpdateSingleProperty)
                        {
                            metaProperties.Remove(deltaLog.propertyName);
                        }
                        else if (metaProperties[deltaLog.propertyName].Item1 == VertexDeltaType.DropPropertyMetaProperty)
                        {
                            // duplicate drop happens, maybe something wrong?
                        }
                    }
                    else
                    {
                        metaProperties[deltaLog.propertyName] = new Tuple <VertexDeltaType, JValue>(VertexDeltaType.DropPropertyMetaProperty, null);
                    }
                }
                else
                {
                    this.deltaProperties[parentName][parentId] = new Tuple <VertexDeltaType, JValue, Dictionary <string, Tuple <VertexDeltaType, JValue> > >(
                        VertexDeltaType.DropPropertyMetaProperty,
                        null,
                        new Dictionary <string, Tuple <VertexDeltaType, JValue> >());
                    this.deltaProperties[parentName][parentId].Item3[deltaLog.propertyName] = new Tuple <VertexDeltaType, JValue>(
                        VertexDeltaType.DropPropertyMetaProperty, null);
                }
            }
            else if (log is DeltaLogUpdateVertexSingleProperty)
            {
                DeltaLogUpdateVertexSingleProperty deltaLog = log as DeltaLogUpdateVertexSingleProperty;
                string name = deltaLog.propertyName;
                string id   = deltaLog.propertyId;

                if (!this.deltaProperties.ContainsKey(name))
                {
                    this.deltaProperties[name] = new Dictionary <string, Tuple <VertexDeltaType, JValue, Dictionary <string, Tuple <VertexDeltaType, JValue> > > >();
                }

                if (!deltaLog.isMultiProperty)
                {
                    this.deltaProperties[name].Clear();
                }

                VertexDeltaType deltaType = VertexDeltaType.UpdateSingleProperty;
                if (deltaLog.isMultiProperty)
                {
                    deltaType = VertexDeltaType.UpdateMultiProperty;
                }

                if (deltaLog.metaProperties.Count > 0)
                {
                    this.deltaProperties[name][id] = new Tuple <VertexDeltaType, JValue, Dictionary <string, Tuple <VertexDeltaType, JValue> > >(
                        deltaType, deltaLog.propertyValue, new Dictionary <string, Tuple <VertexDeltaType, JValue> >());

                    foreach (Tuple <string, JValue> meta in deltaLog.metaProperties)
                    {
                        this.deltaProperties[name][id].Item3[meta.Item1] = new Tuple <VertexDeltaType, JValue>(
                            VertexDeltaType.UpdateSingleProperty, meta.Item2);
                    }
                }
                else
                {
                    this.deltaProperties[name][id] = new Tuple <VertexDeltaType, JValue, Dictionary <string, Tuple <VertexDeltaType, JValue> > >(
                        deltaType, deltaLog.propertyValue, null);
                }
            }
            else if (log is DeltaLogUpdateVertexMetaPropertyOfSingleProperty)
            {
                DeltaLogUpdateVertexMetaPropertyOfSingleProperty deltaLog = log as DeltaLogUpdateVertexMetaPropertyOfSingleProperty;
                string name = deltaLog.propertyName;
                string id   = deltaLog.propertyId;

                if (!this.deltaProperties.ContainsKey(name))
                {
                    this.deltaProperties[name] = new Dictionary <string, Tuple <VertexDeltaType, JValue, Dictionary <string, Tuple <VertexDeltaType, JValue> > > >();
                }

                if (!this.deltaProperties[name].ContainsKey(id))
                {
                    this.deltaProperties[name][id] = new Tuple <VertexDeltaType, JValue, Dictionary <string, Tuple <VertexDeltaType, JValue> > >(
                        VertexDeltaType.UpdateMetaPropertiesOfSingleProperty, null, new Dictionary <string, Tuple <VertexDeltaType, JValue> >());
                }

                Debug.Assert(this.deltaProperties[name][id].Item1 != VertexDeltaType.DropSingleProperty);
                Debug.Assert(this.deltaProperties[name][id].Item3 != null);

                foreach (Tuple <string, JValue> meta in deltaLog.metaProperties)
                {
                    this.deltaProperties[name][id].Item3[meta.Item1] = new Tuple <VertexDeltaType, JValue>(
                        VertexDeltaType.UpdateMetaPropertiesOfSingleProperty, meta.Item2);
                }
            }
        }
예제 #5
0
        internal void AddOrUpdateEdgeDelta(EdgeField outEdgeField, VertexField srcVertexField,
                                           EdgeField inEdgeField, VertexField sinkVertexField, DeltaLog log, bool useReverseEdges)
        {
            string edgeId = outEdgeField.EdgeId;

            DeltaEdgeField delta;

            if (edgeDelta.ContainsKey(edgeId))
            {
                delta = edgeDelta[edgeId];
            }
            else
            {
                delta             = new DeltaEdgeField(outEdgeField, srcVertexField, inEdgeField, sinkVertexField, useReverseEdges);
                edgeDelta[edgeId] = delta;
            }
            delta.AddDeltaLog(log);
        }
예제 #6
0
        public void DeltaLogTest1()
        {
            int           TotalCount = 1000;
            string        path       = TestContext.CurrentContext.TestDirectory + "/" + TestContext.CurrentContext.Test.Name + "/";
            DirectoryInfo di         = Directory.CreateDirectory(path);

            using (IDevice device = Devices.CreateLogDevice(path + TestContext.CurrentContext.Test.Name + "/delta.log", deleteOnClose: false))
            {
                device.Initialize(-1);
                using DeltaLog deltaLog = new DeltaLog(device, 12, 0);
                Random r = new Random(20);
                int    i;

                var bufferPool = new SectorAlignedBufferPool(1, (int)device.SectorSize);
                deltaLog.InitializeForWrites(bufferPool);
                for (i = 0; i < TotalCount; i++)
                {
                    int  len = 1 + r.Next(254);
                    long address;
                    while (true)
                    {
                        deltaLog.Allocate(out int maxLen, out address);
                        if (len <= maxLen)
                        {
                            break;
                        }
                        deltaLog.Seal(0);
                    }
                    for (int j = 0; j < len; j++)
                    {
                        unsafe { *(byte *)(address + j) = (byte)len; }
                    }
                    deltaLog.Seal(len, i);
                }
                deltaLog.FlushAsync().Wait();

                deltaLog.InitializeForReads();
                i = 0;
                r = new Random(20);
                while (deltaLog.GetNext(out long address, out int len, out int type))
                {
                    int _len = 1 + r.Next(254);
                    Assert.IsTrue(type == i);
                    Assert.IsTrue(_len == len);
                    for (int j = 0; j < len; j++)
                    {
                        unsafe { Assert.IsTrue(*(byte *)(address + j) == (byte)_len); };
                    }
                    i++;
                }
                Assert.IsTrue(i == TotalCount);
                bufferPool.Free();
            }
            while (true)
            {
                try
                {
                    di.Delete(recursive: true);
                    break;
                }
                catch { }
            }
        }