protected override BlittableJsonReaderObject GetUpdatedValue(long index, RawDatabaseRecord record, JsonOperationContext context, BlittableJsonReaderObject existingValue)
        {
            var itemId = GetItemId();

            if (existingValue == null)
            {
                throw new SubscriptionDoesNotExistException($"Subscription with id '{itemId}' does not exist");
            }

            var subscription = JsonDeserializationCluster.SubscriptionState(existingValue);

            var topology            = record.Topology;
            var lastResponsibleNode = AcknowledgeSubscriptionBatchCommand.GetLastResponsibleNode(HasHighlyAvailableTasks, topology, NodeTag);
            var appropriateNode     = topology.WhoseTaskIsIt(RachisState.Follower, subscription, lastResponsibleNode);

            if (appropriateNode == null && record.DeletionInProgress.ContainsKey(NodeTag))
            {
                throw new DatabaseDoesNotExistException(
                          $"Stopping subscription '{SubscriptionName}' on node {NodeTag}, because database '{DatabaseName}' is being deleted.");
            }

            if (appropriateNode != NodeTag)
            {
                throw new SubscriptionDoesNotBelongToNodeException(
                          $"Can't update subscription with name {itemId} by node {NodeTag}, because it's not its task to update this subscription");
            }

            subscription.LastClientConnectionTime = LastClientConnectionTime;
            subscription.NodeTag = NodeTag;

            return(context.ReadObject(subscription.ToJson(), itemId));
        }
        protected override BlittableJsonReaderObject GetUpdatedValue(long index, DatabaseRecord record, JsonOperationContext context, BlittableJsonReaderObject existingValue, bool isPassive)
        {
            var subscriptionName = SubscriptionName;

            if (string.IsNullOrEmpty(subscriptionName))
            {
                subscriptionName = SubscriptionId.ToString();
            }

            if (existingValue == null)
            {
                throw new InvalidOperationException($"Subscription with name {subscriptionName} does not exist");
            }

            var subscription = JsonDeserializationCluster.SubscriptionState(existingValue);

            if (record.Topology.WhoseTaskIsIt(subscription, isPassive) != NodeTag)
            {
                throw new InvalidOperationException($"Can't update subscription with name {subscriptionName} by node {NodeTag}, because it's not it's task to update this subscription");
            }


            if (LastKnownSubscriptionChangeVector != subscription.ChangeVectorForNextBatchStartingPoint)
            {
                throw new ConcurrencyException($"Can't acknowledge subscription with name {subscriptionName} due to inconsistency in change vector progress. Probably there was an admin intervention that changed the change vector value");
            }

            subscription.ChangeVectorForNextBatchStartingPoint = ChangeVector;

            subscription.LastTimeServerMadeProgressWithDocuments = LastTimeServerMadeProgressWithDocuments;

            return(context.ReadObject(subscription.ToJson(), subscriptionName));
        }
Exemple #3
0
        protected override BlittableJsonReaderObject GetUpdatedValue(long index, RawDatabaseRecord record, JsonOperationContext context, BlittableJsonReaderObject existingValue)
        {
            var subscriptionName = SubscriptionName;

            if (string.IsNullOrEmpty(subscriptionName))
            {
                subscriptionName = SubscriptionId.ToString();
            }

            if (existingValue == null)
            {
                throw new SubscriptionDoesNotExistException($"Subscription with name '{subscriptionName}' does not exist");
            }

            var subscription        = JsonDeserializationCluster.SubscriptionState(existingValue);
            var topology            = record.Topology;
            var lastResponsibleNode = GetLastResponsibleNode(HasHighlyAvailableTasks, topology, NodeTag);
            var appropriateNode     = topology.WhoseTaskIsIt(RachisState.Follower, subscription, lastResponsibleNode);

            if (appropriateNode == null && record.DeletionInProgress.ContainsKey(NodeTag))
            {
                throw new DatabaseDoesNotExistException($"Stopping subscription '{subscriptionName}' on node {NodeTag}, because database '{DatabaseName}' is being deleted.");
            }

            if (appropriateNode != NodeTag)
            {
                throw new SubscriptionDoesNotBelongToNodeException(
                          $"Cannot apply {nameof(AcknowledgeSubscriptionBatchCommand)} for subscription '{subscriptionName}' with id '{SubscriptionId}', on database '{DatabaseName}', on node '{NodeTag}'," +
                          $" because the subscription task belongs to '{appropriateNode ?? "N/A"}'.")
                      {
                          AppropriateNode = appropriateNode
                      };
            }

            if (ChangeVector == nameof(Constants.Documents.SubscriptionChangeVectorSpecialStates.DoNotChange))
            {
                return(context.ReadObject(existingValue, SubscriptionName));
            }

            if (IsLegacyCommand())
            {
                if (LastKnownSubscriptionChangeVector != subscription.ChangeVectorForNextBatchStartingPoint)
                {
                    throw new SubscriptionChangeVectorUpdateConcurrencyException($"Can't acknowledge subscription with name {subscriptionName} due to inconsistency in change vector progress. Probably there was an admin intervention that changed the change vector value. Stored value: {subscription.ChangeVectorForNextBatchStartingPoint}, received value: {LastKnownSubscriptionChangeVector}");
                }

                subscription.ChangeVectorForNextBatchStartingPoint = ChangeVector;
            }

            subscription.NodeTag          = NodeTag;
            subscription.LastBatchAckTime = LastTimeServerMadeProgressWithDocuments;

            return(context.ReadObject(subscription.ToJson(), subscriptionName));
        }
Exemple #4
0
        protected override BlittableJsonReaderObject GetUpdatedValue(long index, DatabaseRecord record, JsonOperationContext context, BlittableJsonReaderObject existingValue, bool isPassive)
        {
            var itemId = GetItemId();

            if (existingValue == null)
            {
                throw new InvalidOperationException($"Subscription with id {itemId} does not exist");
            }

            if (record.Topology.WhoseTaskIsIt(this, isPassive) != NodeTag)
            {
                throw new InvalidOperationException($"Can't update subscription with name {itemId} by node {NodeTag}, because it's not it's task to update this subscription");
            }

            var subscription = JsonDeserializationCluster.SubscriptionState(existingValue);

            subscription.LastClientConnectionTime = LastClientConnectionTime;

            return(context.ReadObject(subscription.ToJson(), itemId));
        }
Exemple #5
0
        protected override BlittableJsonReaderObject GetUpdatedValue(long index, RawDatabaseRecord record, JsonOperationContext context, BlittableJsonReaderObject existingValue)
        {
            var subscriptionName = SubscriptionName;

            if (string.IsNullOrEmpty(subscriptionName))
            {
                subscriptionName = SubscriptionId.ToString();
            }

            if (existingValue == null)
            {
                throw new SubscriptionDoesNotExistException($"Subscription with name {subscriptionName} does not exist");
            }

            var subscription = JsonDeserializationCluster.SubscriptionState(existingValue);

            var topology            = record.Topology;
            var lastResponsibleNode = GetLastResponsibleNode(HasHighlyAvailableTasks, topology, NodeTag);

            if (topology.WhoseTaskIsIt(RachisState.Follower, subscription, lastResponsibleNode) != NodeTag)
            {
                throw new SubscriptionDoesNotBelongToNodeException($"Can't update subscription with name {subscriptionName} by node {NodeTag}, because it's not its task to update this subscription");
            }

            if (ChangeVector == nameof(Constants.Documents.SubscriptionChangeVectorSpecialStates.DoNotChange))
            {
                return(context.ReadObject(existingValue, SubscriptionName));
            }

            if (LastKnownSubscriptionChangeVector != subscription.ChangeVectorForNextBatchStartingPoint)
            {
                throw new SubscriptionChangeVectorUpdateConcurrencyException($"Can't acknowledge subscription with name {subscriptionName} due to inconsistency in change vector progress. Probably there was an admin intervention that changed the change vector value. Stored value: {subscription.ChangeVectorForNextBatchStartingPoint}, received value: {LastKnownSubscriptionChangeVector}");
            }

            subscription.ChangeVectorForNextBatchStartingPoint = ChangeVector;
            subscription.NodeTag          = NodeTag;
            subscription.LastBatchAckTime = LastTimeServerMadeProgressWithDocuments;

            return(context.ReadObject(subscription.ToJson(), subscriptionName));
        }
        protected override BlittableJsonReaderObject GetUpdatedValue(long index, DatabaseRecord record, JsonOperationContext context, BlittableJsonReaderObject existingValue, RachisState state)
        {
            var itemId = GetItemId();

            if (existingValue == null)
            {
                throw new RachisApplyException($"Subscription with id {itemId} does not exist");
            }

            var subscription = JsonDeserializationCluster.SubscriptionState(existingValue);

            var lastResponsibleNode = AcknowledgeSubscriptionBatchCommand.GetLastResponsibleNode(HasHighlyAvailableTasks, record.Topology, NodeTag);

            if (record.Topology.WhoseTaskIsIt(state, subscription, lastResponsibleNode) != NodeTag)
            {
                throw new RachisApplyException($"Can't update subscription with name {itemId} by node {NodeTag}, because it's not it's task to update this subscription");
            }

            subscription.LastClientConnectionTime = LastClientConnectionTime;
            subscription.NodeTag = NodeTag;

            return(context.ReadObject(subscription.ToJson(), itemId));
        }