Beispiel #1
0
        public void AfterAddInDifferentTxValueDoesNotExists()
        {
            Assert.True(Table.Put(RavenJToken.FromObject("123"), new byte[] { 1, 2, 4, 5 }));

            Table.ReadResult data = null;
            SupressTx(() => data = Table.Read(RavenJToken.FromObject("123")));
            Assert.Null(data);
        }
Beispiel #2
0
        public void BeforeCommitRemoveIsNotVisibleOutsideTheTx()
        {
            Assert.True(Table.Put(RavenJToken.FromObject("123"), new byte[] { 1, 2, 4, 5 }));

            Commit();

            Assert.True(Table.Remove(RavenJToken.FromObject("123")));

            Table.ReadResult data = null;
            SupressTx(() => data = Table.Read(RavenJToken.FromObject("123")));

            Assert.Equal(new byte[] { 1, 2, 4, 5 }, data.Data());
        }
Beispiel #3
0
 public IndexStats GetIndexStats(string index)
 {
     using (storage.ReadLock())
     {
         var readResult = storage.IndexingStats.Read(new RavenJObject {
             { "index", index }
         });
         if (readResult == null)
         {
             return(null);
         }
         Table.ReadResult lastIndexedEtagReadResult = storage.LastIndexedEtags.Read(new RavenJObject {
             { "index", index }
         });
         return(GetIndexStats(readResult, lastIndexedEtagReadResult));
     }
 }
Beispiel #4
0
        private bool IsModifiedByTransaction(Table.ReadResult resultInTx)
        {
            if (resultInTx == null)
            {
                return(false);
            }
            var txId = resultInTx.Key.Value <byte[]>("txId");
            var tx   = storage.Transactions.Read(new RavenJObject
            {
                { "txId", txId }
            });

            if (tx == null)
            {
                return(false);
            }
            return(SystemTime.UtcNow < tx.Key.Value <DateTime>("timeout"));
        }
Beispiel #5
0
 private static IndexStats GetIndexStats(Table.ReadResult readResult)
 {
     return(new IndexStats
     {
         TouchCount = readResult.Key.Value <int>("touches"),
         IndexingAttempts = readResult.Key.Value <int>("attempts"),
         IndexingErrors = readResult.Key.Value <int>("failures"),
         IndexingSuccesses = readResult.Key.Value <int>("successes"),
         ReduceIndexingAttempts = readResult.Key.Value <int?>("reduce_attempts"),
         ReduceIndexingErrors = readResult.Key.Value <int?>("reduce_failures"),
         ReduceIndexingSuccesses = readResult.Key.Value <int?>("reduce_successes"),
         Name = readResult.Key.Value <string>("index"),
         LastIndexedEtag = new Guid(readResult.Key.Value <byte[]>("lastEtag")),
         LastIndexedTimestamp = readResult.Key.Value <DateTime>("lastTimestamp"),
         LastReducedEtag =
             readResult.Key.Value <byte[]>("lastReducedEtag") != null
                                         ? (Guid?)new Guid(readResult.Key.Value <byte[]>("lastReducedEtag"))
                                         : null,
         LastReducedTimestamp = readResult.Key.Value <DateTime?>("lastReducedTimestamp")
     });
 }
        private static void AssertValidEtag(string key, Table.ReadResult doc, Table.ReadResult docInTx, Guid?etag)
        {
            if (doc == null)
            {
                return;
            }
            var existingEtag =
                docInTx != null
                                        ? new Guid(docInTx.Key.Value <byte[]>("etag"))
                                        : new Guid(doc.Key.Value <byte[]>("etag"));


            if (etag != null && etag.Value != existingEtag)
            {
                throw new ConcurrencyException("PUT attempted on document '" + key +
                                               "' using a non current etag")
                      {
                          ActualETag   = existingEtag,
                          ExpectedETag = etag.Value
                      };
            }
        }
Beispiel #7
0
 private static IndexStats GetIndexStats(Table.ReadResult indexingStatsResult, Table.ReadResult lastIndexedEtagsResult)
 {
     return(new IndexStats
     {
         TouchCount = indexingStatsResult.Key.Value <int>("touches"),
         IndexingAttempts = indexingStatsResult.Key.Value <int>("attempts"),
         IndexingErrors = indexingStatsResult.Key.Value <int>("failures"),
         IndexingSuccesses = indexingStatsResult.Key.Value <int>("successes"),
         ReduceIndexingAttempts = indexingStatsResult.Key.Value <int?>("reduce_attempts"),
         ReduceIndexingErrors = indexingStatsResult.Key.Value <int?>("reduce_failures"),
         ReduceIndexingSuccesses = indexingStatsResult.Key.Value <int?>("reduce_successes"),
         Name = indexingStatsResult.Key.Value <string>("index"),
         Priority = (IndexingPriority)indexingStatsResult.Key.Value <int>("priority"),
         LastIndexedEtag = Etag.Parse(lastIndexedEtagsResult.Key.Value <byte[]>("lastEtag")),
         LastIndexedTimestamp = lastIndexedEtagsResult.Key.Value <DateTime>("lastTimestamp"),
         CreatedTimestamp = indexingStatsResult.Key.Value <DateTime>("createdTimestamp"),
         LastIndexingTime = indexingStatsResult.Key.Value <DateTime>("lastIndexingTime"),
         LastReducedEtag =
             indexingStatsResult.Key.Value <byte[]>("lastReducedEtag") != null
                                         ? Etag.Parse(indexingStatsResult.Key.Value <byte[]>("lastReducedEtag"))
                                         : null,
         LastReducedTimestamp = indexingStatsResult.Key.Value <DateTime?>("lastReducedTimestamp")
     });
 }
Beispiel #8
0
        public static void AssertNotModifiedByAnotherTransaction(TableStorage storage, ITransactionStorageActions transactionStorageActions, string key, Table.ReadResult readResult, TransactionInformation transactionInformation)
        {
            if (readResult == null)
            {
                return;
            }
            var txIdAsBytes = readResult.Key.Value <byte[]>("txId");

            if (txIdAsBytes == null)
            {
                return;
            }

            var txId = new Guid(txIdAsBytes);

            if (transactionInformation != null && transactionInformation.Id == txId)
            {
                return;
            }

            var existingTx = storage.Transactions.Read(new RavenJObject {
                { "txId", txId.ToByteArray() }
            });

            if (existingTx == null)//probably a bug, ignoring this as not a real tx
            {
                return;
            }

            var timeout = existingTx.Key.Value <DateTime>("timeout");

            if (DateTime.UtcNow > timeout)
            {
                transactionStorageActions.RollbackTransaction(txId);
                return;
            }

            throw new ConcurrencyException("Document '" + key + "' is locked by transacton: " + txId);
        }
Beispiel #9
0
        private static void UseMyData()
        {
            using (var d = new MyData(new MemoryPersistentSource()))
            {
                using (d.BeginTransaction())
                {
                    d.Documents.Put(new RavenJObject
                    {
                        { "key", "items/1" },
                        { "id", "items/1" },
                        { "etag", Guid.NewGuid().ToByteArray() },
                    }, new byte[0]);
                    d.Commit();
                }

                using (d.BeginTransaction())
                {
                    d.Documents.Put(new RavenJObject
                    {
                        { "key", "items/1" },
                        { "id", "items/1" },
                        { "etag", Guid.NewGuid().ToByteArray() },
                        { "txId", "1234" }
                    }, new byte[0]);
                    d.Transactions.Put(new RavenJObject
                    {
                        { "id", "1234" },
                    }, new byte[0]);

                    d.Commit();
                }

                ThreadPool.QueueUserWorkItem(state =>
                {
                    d.BeginTransaction();
                    Table.ReadResult readResult = d.Documents.Read(new RavenJObject {
                        { "key", "items/1" }
                    });
                    var txId = readResult.Key.Value <string>("txId");

                    Table.ReadResult txResult = d.Transactions.Read(new RavenJObject {
                        { "id", txId }
                    });

                    if (txResult == null)
                    {
                        Environment.Exit(1);
                        return;
                    }

                    d.Transactions.Remove(txResult.Key);

                    var x = ((RavenJObject)readResult.Key.CloneToken());
                    x.Remove("txId");

                    d.Documents.UpdateKey(x);
                    d.CommitCurrentTransaction();
                });


                while (true)
                {
                    using (d.BeginTransaction())
                    {
                        Table.ReadResult readResult = d.Documents.Read(new RavenJObject {
                            { "key", "items/1" }
                        });
                        var txId = readResult.Key.Value <string>("txId");

                        if (txId == null)
                        {
                            return;
                        }

                        Table.ReadResult txResult = d.Transactions.Read(new RavenJObject {
                            { "id", txId }
                        });
                        if (txResult == null)
                        {
                            Environment.Exit(1);
                            return;
                        }

                        d.Commit();
                    }
                }
            }
        }