Exemple #1
0
        public ClusterTransactionCommand(string databaseName, char identityPartsSeparator, DatabaseTopology topology,
                                         ArraySegment <BatchRequestParser.CommandData> commandParsedCommands,
                                         ClusterTransactionOptions options, string uniqueRequestId) : base(uniqueRequestId)
        {
            DatabaseName         = databaseName;
            DatabaseRecordId     = topology.DatabaseTopologyIdBase64 ?? Guid.NewGuid().ToBase64Unpadded();
            ClusterTransactionId = topology.ClusterTransactionIdBase64 ?? Guid.NewGuid().ToBase64Unpadded();
            Options = options;
            CommandCreationTicks = SystemTime.UtcNow.Ticks;

            foreach (var commandData in commandParsedCommands)
            {
                var command = ClusterTransactionDataCommand.FromCommandData(commandData);
                ClusterCommandValidation(command, identityPartsSeparator);
                switch (commandData.Type)
                {
                case CommandType.PUT:
                case CommandType.DELETE:
                    DatabaseCommands.Add(command);
                    break;

                case CommandType.CompareExchangePUT:
                case CommandType.CompareExchangeDELETE:
                    ClusterCommands.Add(command);
                    break;

                default:
                    throw new RachisApplyException($"The type '{commandData.Type}' is not supported in '{nameof(ClusterTransactionCommand)}.'");
                }
            }

            DatabaseCommandsCount = DatabaseCommands.Count;
        }
        public ClusterTransactionCommand(string databaseName, string recordId, ArraySegment <BatchRequestParser.CommandData> commandParsedCommands,
                                         ClusterTransactionOptions options)
        {
            DatabaseName     = databaseName;
            DatabaseRecordId = recordId ?? Guid.NewGuid().ToBase64Unpadded();
            Options          = options;

            foreach (var commandData in commandParsedCommands)
            {
                var command = ClusterTransactionDataCommand.FromCommandData(commandData);
                ClusterCommandValidation(command);
                switch (commandData.Type)
                {
                case CommandType.PUT:
                case CommandType.DELETE:
                    DatabaseCommands.Add(command);
                    break;

                case CommandType.CompareExchangePUT:
                case CommandType.CompareExchangeDELETE:
                    ClusterCommands.Add(command);
                    break;

                default:
                    throw new RachisApplyException($"The type '{commandData.Type}' is not supported in '{nameof(ClusterTransactionCommand)}.'");
                }
            }

            DatabaseCommandsCount = DatabaseCommands.Count;
        }
        private static unsafe SingleClusterDatabaseCommand ReadCommand(TransactionOperationContext context, TableValueReader reader)
        {
            var ptr = reader.Read((int)TransactionCommandsColumn.Commands, out var size);

            if (ptr == null)
            {
                return(null);
            }

            var blittable = new BlittableJsonReaderObject(ptr, size, context);

            blittable.TryGet(nameof(DatabaseCommands), out BlittableJsonReaderArray array);

            ClusterTransactionOptions options = null;

            if (blittable.TryGet(nameof(Options), out BlittableJsonReaderObject blittableOptions))
            {
                options = JsonDeserializationServer.ClusterTransactionOptions(blittableOptions);
            }

            var index    = *(long *)reader.Read((int)TransactionCommandsColumn.RaftIndex, out _);
            var keyPtr   = reader.Read((int)TransactionCommandsColumn.Key, out size);
            var database = Encoding.UTF8.GetString(keyPtr, size - sizeof(long) - 1);

            return(new SingleClusterDatabaseCommand
            {
                Options = options,
                Commands = array,
                Index = index,
                PreviousCount = Bits.SwapBytes(*(long *)(keyPtr + size - sizeof(long))),
                Database = database
            });
        }
Exemple #4
0
        public ClusterTransactionCommand(string database, ArraySegment <BatchRequestParser.CommandData> commandParsedCommands, ClusterTransactionOptions options)
        {
            Database = database;
            Options  = options;

            foreach (var commandData in commandParsedCommands)
            {
                var command = ClusterTransactionDataCommand.FromCommandData(commandData);
                ClusterCommandValidation(command);
                switch (commandData.Type)
                {
                case CommandType.PUT:
                case CommandType.DELETE:
                    DatabaseCommands.Add(command);
                    break;

                case CommandType.CompareExchangePUT:
                case CommandType.CompareExchangeDELETE:
                    ClusterCommands.Add(command);
                    break;

                default:
                    throw new ArgumentException($"The type '{commandData.Type}' is not supported in '{nameof(ClusterTransactionCommand)}.'");
                }
            }

            DatabaseCommandsCount = DatabaseCommands.Count;
        }