public override void SetResponse(JsonOperationContext context, BlittableJsonReaderObject response, bool fromCache) { if (response == null) { Result = null; return; } _session.AssertNotDisposed(); // verify that we don't have async query with the user closing the session if (fromCache) { // we have to clone the response here because otherwise the cached item might be freed while // we are still looking at this result, so we clone it to the side response = response.Clone(context); } Result = JsonDeserializationClient.QueryResult(response); if (fromCache) { Result.DurationInMs = -1; if (Result.Timings != null) { Result.Timings.DurationInMs = -1; Result.Timings = null; } } }
public override unsafe (long Index, object Value) Execute(TransactionOperationContext context, Table items, long index) { // We have to clone the Value because we might have gotten this command from another node // and it was serialized. In that case, it is an _internal_ object, not a full document, // so we have to clone it to get it into a standalone mode. Value = Value.Clone(context); using (Slice.From(context.Allocator, ActualKey, out Slice keySlice)) using (items.Allocate(out TableValueBuilder tvb)) { tvb.Add(keySlice.Content.Ptr, keySlice.Size); tvb.Add(index); tvb.Add(Value.BasePointer, Value.Size); if (items.ReadByKey(keySlice, out var reader)) { var itemIndex = *(long *)reader.Read((int)ClusterStateMachine.UniqueItems.Index, out var _); if (Index == itemIndex) { items.Update(reader.Id, tvb); } else { // concurrency violation, so we return the current value return(itemIndex, new BlittableJsonReaderObject(reader.Read((int)ClusterStateMachine.UniqueItems.Value, out var size), size, context)); } } else { items.Set(tvb); } } return(index, Value); }
public override unsafe (long Index, object Value) Execute(TransactionOperationContext context, Table items, long index) { var dbKey = Key.ToLowerInvariant(); Value = Value.Clone(context); long itemIndex; using (Slice.From(context.Allocator, dbKey, out Slice keySlice)) using (items.Allocate(out TableValueBuilder tvb)) { tvb.Add(keySlice.Content.Ptr, keySlice.Size); tvb.Add(index); tvb.Add(Value.BasePointer, Value.Size); if (items.ReadByKey(keySlice, out var reader)) { itemIndex = *(long *)reader.Read((int)ClusterStateMachine.UniqueItems.Index, out var _); if (Index == itemIndex) { items.Update(reader.Id, tvb); } else { // concurrency violation, so we return the current value return(itemIndex, new BlittableJsonReaderObject(reader.Read((int)ClusterStateMachine.UniqueItems.Value, out var size), size, context)); } } else { items.Set(tvb); } } return(index, Value); }
public unsafe void SaveCommandsBatch(TransactionOperationContext context, long index) { if (SerializedDatabaseCommands == null || DatabaseCommandsCount == 0) { return; } var items = context.Transaction.InnerTransaction.OpenTable(ClusterStateMachine.TransactionCommandsSchema, ClusterStateMachine.TransactionCommands); var commandsCountPerDatabase = context.Transaction.InnerTransaction.ReadTree(ClusterStateMachine.TransactionCommandsCountPerDatabase); var commands = SerializedDatabaseCommands.Clone(context); using (GetPrefix(context, DatabaseName, out var databaseSlice)) { var count = commandsCountPerDatabase.ReadLong(databaseSlice) ?? 0; using (GetPrefix(context, DatabaseName, out var prefixSlice, count)) using (items.Allocate(out TableValueBuilder tvb)) { tvb.Add(prefixSlice.Content.Ptr, prefixSlice.Size); tvb.Add(commands.BasePointer, commands.Size); tvb.Add(index); items.Insert(tvb); using (commandsCountPerDatabase.DirectAdd(databaseSlice, sizeof(long), out var ptr)) *(long *)ptr = count + DatabaseCommandsCount; } } }
protected override ReplicationBatchItem CloneInternal(JsonOperationContext context) { return(new CounterReplicationItem { Values = Values?.Clone(context), Collection = Collection, Id = Id }); }
protected override ReplicationBatchItem CloneInternal(JsonOperationContext context) { return(new DocumentReplicationItem { Id = Id, Data = Data?.Clone(context), Collection = Collection, Flags = Flags }); }
public DynamicJsonValue ToJson(JsonOperationContext context) { return(new DynamicJsonValue { [nameof(Type)] = Type, [nameof(Id)] = Id, [nameof(Index)] = Index, [nameof(ChangeVector)] = ChangeVector, [nameof(Document)] = Document?.Clone(context) }); }
public override void SetResponse(JsonOperationContext context, BlittableJsonReaderObject response, bool fromCache) { if (response == null) { return; } if (fromCache) { // we have to clone the response here because otherwise the cached item might be freed while // we are still looking at this result, so we clone it to the side response = response.Clone(context); } Result = JsonDeserializationClient.JsonPatchResult(response); }
public override void SetResponse(JsonOperationContext context, BlittableJsonReaderObject response, bool fromCache) { if (response == null) { throw new InvalidOperationException("Got null response from the server after doing a batch, something is very wrong. Probably a garbled response."); } // this should never actually occur, we are not caching the response of batch commands, but keeping it here anyway if (fromCache) { // we have to clone the response here because otherwise the cached item might be freed while // we are still looking at this result, so we clone it to the side response = response.Clone(context); } Result = JsonDeserializationClient.BatchCommandResult(response); }
public Document Clone(DocumentsOperationContext context) { return(new Document { Etag = Etag, StorageId = StorageId, IndexScore = IndexScore, Distance = Distance, ChangeVector = ChangeVector, LastModified = LastModified, Flags = Flags, NonPersistentFlags = NonPersistentFlags, TransactionMarker = TransactionMarker, Id = context.GetLazyString(Id), LowerId = context.GetLazyString(LowerId), Data = Data.Clone(context), }); }
public override unsafe (long Index, object Value) Execute(TransactionOperationContext context, Table items, long index) { using (Slice.From(context.Allocator, ActualKey, out Slice keySlice)) { if (items.ReadByKey(keySlice, out var reader)) { var itemIndex = *(long *)reader.Read((int)ClusterStateMachine.UniqueItems.Index, out var _); var storeValue = reader.Read((int)ClusterStateMachine.UniqueItems.Value, out var size); var result = new BlittableJsonReaderObject(storeValue, size, context); if (Index == itemIndex) { result = result.Clone(context); items.Delete(reader.Id); return(index, result); } return(itemIndex, result); } } return(index, null); }
public override DynamicJsonValue ToJson(JsonOperationContext context) { var djv = base.ToJson(context); djv[nameof(ClusterCommands)] = new DynamicJsonArray(ClusterCommands.Select(x => x.ToJson(context))); djv[nameof(SerializedDatabaseCommands)] = SerializedDatabaseCommands?.Clone(context); if (SerializedDatabaseCommands == null && DatabaseCommands.Count > 0) { var databaseCommands = new DynamicJsonValue { [nameof(DatabaseCommands)] = new DynamicJsonArray(DatabaseCommands.Select(x => x.ToJson(context))), [nameof(Options)] = Options.ToJson(), }; djv[nameof(SerializedDatabaseCommands)] = context.ReadObject(databaseCommands, "read database commands"); } djv[nameof(Database)] = Database; djv[nameof(DatabaseCommandsCount)] = DatabaseCommandsCount; return(djv); }
private BlittableJsonReaderObject GetCleanMetadata(BlittableJsonReaderObject metadata, DocumentsOperationContext context) { using (var old = metadata) metadata = metadata.Clone(context); metadata.Modifications = new DynamicJsonValue(metadata); metadata.Modifications.Remove("Origin"); metadata.Modifications.Remove("Raven-Synchronization-Version"); metadata.Modifications.Remove("Raven-Synchronization-Source"); metadata.Modifications.Remove("Creation-Date"); metadata.Modifications.Remove("Raven-Creation-Date"); metadata.Modifications.Remove("Raven-Synchronization-History"); metadata.Modifications.Remove("RavenFS-Size"); metadata.Modifications.Remove("Last-Modified"); metadata.Modifications.Remove("Raven-Last-Modified"); metadata.Modifications.Remove("Content-MD5"); metadata.Modifications.Remove("ETag"); using (var old = metadata) return(context.ReadObject(metadata, Options.MigrationStateKey)); }
private BlittableJsonReaderObject Clone(BlittableJsonReaderObject origin, JsonOperationContext context) { if (ReadOnly) { return(origin); } var noCache = origin.NoCache; origin.NoCache = true; // RavenDB-8286 // here we need to make sure that we aren't sending a value to // the js engine that might be modified by the actions of the js engine // for example, calling put() might cause the original data to change // because we defrag the data that we looked at. We are handling this by // ensuring that we have our own, safe, copy. var cloned = origin.Clone(context); cloned.NoCache = true; _disposables.Add(cloned); origin.NoCache = noCache; return(cloned); }
public Document Clone(JsonOperationContext context) { var newData = Data.Clone(context); return(CloneWith(context, newData)); }