예제 #1
0
        public void test_merge_context()
        {
            var dst = new LinRead();

            dst.Ids.Add(new Dictionary <uint, ulong>
            {
                { 1, 10L },
                { 2, 15L },
                { 3, 10L }
            });

            var src = new LinRead();

            src.Ids.Add(new Dictionary <uint, ulong>
            {
                { 2, 10L },
                { 3, 15L },
                { 4, 10L }
            });

            var result = DgraphNetClient.MergeLinReads(dst, src);

            Assert.AreEqual(4, result.Ids.Count);

            Assert.AreEqual(10L, result.Ids[1]);
            Assert.AreEqual(15L, result.Ids[2]);
            Assert.AreEqual(15L, result.Ids[3]);
            Assert.AreEqual(10L, result.Ids[4]);
        }
예제 #2
0
            private void MergeContext(TxnContext src)
            {
                TxnContext result = new TxnContext(_context);

                LinRead lr = MergeLinReads(_context.LinRead, src.LinRead);

                result.LinRead = lr;

                lock (_client._lock)
                {
                    lr = MergeLinReads(_client._linRead, lr);
                    _client._linRead = lr;
                }

                if (_context.StartTs == 0)
                {
                    result.StartTs = src.StartTs;
                }
                else if (_context.StartTs != src.StartTs)
                {
                    _context = result;
                    throw new DgraphException("StartTs mismatch");
                }

                result.Keys.Add(src.Keys);

                _context = result;
            }
예제 #3
0
 private LinRead GetLinReadCopy()
 {
     lock (_lock)
     {
         LinRead lr = new LinRead(_linRead);
         return(lr);
     }
 }
예제 #4
0
        internal LinRead GetLinRead()
        {
            LinRead lr;

            lock (LinReadMutex) {
                lr = new LinRead(linRead);
            }
            return(lr);
        }
예제 #5
0
        internal static void MergeLinReads(LinRead dst, LinRead src)
        {
            if (src == null || src.Ids == null)
            {
                return;
            }

            foreach (var entry in src.Ids)
            {
                if (dst.Ids.TryGetValue(entry.Key, out var did) && (did >= entry.Value))
                {
                    // do nothing
                }
                else
                {
                    dst.Ids[entry.Key] = entry.Value;
                }
            }
        }
예제 #6
0
        public static LinRead MergeLinReads(LinRead dst, LinRead src)
        {
            LinRead result = new LinRead(dst);

            foreach (var entry in src.Ids)
            {
                if (dst.Ids.TryGetValue(entry.Key, out ulong dstValue))
                {
                    if (dstValue < entry.Value)
                    {
                        result.Ids[entry.Key] = entry.Value;
                    }
                }
                else
                {
                    result.Ids.Add(entry.Key, entry.Value);
                }
            }
            return(result);
        }
예제 #7
0
 internal void MergeLinRead(LinRead newLinRead)
 {
     lock (LinReadMutex) {
         Transaction.MergeLinReads(linRead, newLinRead);
     }
 }
예제 #8
0
 internal DgraphClient(IGRPCConnectionFactory connectionFactory, ITransactionFactory transactionFactory)
 {
     this.connectionFactory  = connectionFactory;
     this.transactionFactory = transactionFactory;
     linRead = new LinRead();
 }
예제 #9
0
 private DgraphNetClient()
 {
     _linRead = new LinRead();
 }