void ReplicatedStore::TransactionBase::OperationFailed(ErrorCode const & error)
    {
        // Enables implementation of more efficient TryInsert(), TryUpdate(), and TryDelete() patterns.
        //
        if (!error.IsError(ErrorCodeValue::StoreRecordAlreadyExists) && !error.IsError(ErrorCodeValue::StoreRecordNotFound))
        {
            this->OnOperationFailed(error);

            if (error.IsError(ErrorCodeValue::StoreFatalError))
            {
                replicatedStore_.ReportTransientFault(error);
            }
        }
    }
ErrorCode FileStoreServiceReplica::CreateName()
{     
    ManualResetEvent operationDone;
    ErrorCode error;

    propertyManagmentClient_->BeginCreateName(
        NamingUri(serviceName_),
        FileStoreServiceConfig::GetConfig().NamingOperationTimeout,
        [this, &error, &operationDone] (AsyncOperationSPtr const & operation)
    {
        error = propertyManagmentClient_->EndCreateName(operation);
        WriteInfo(
            TraceComponent,
            this->TraceId,
            "CreateName: Error:{0}",
            error);
        operationDone.Set();
    },
        this->CreateAsyncOperationRoot());
    
    operationDone.WaitOne();
    
    if(!error.IsSuccess() && !error.IsError(ErrorCodeValue::NameAlreadyExists))
    {
        return error;
    }

    return ErrorCodeValue::Success;
}
ErrorCode HostingQueryManager::ReplaceErrorIf(ErrorCode actualError, ErrorCodeValue::Enum compareWithError, ErrorCodeValue::Enum changeToError)
{
    if (actualError.IsError(compareWithError))
    {
        return changeToError;
    }

    return actualError;
}
void RequestReceiverContext::Reject(ErrorCode const & error, ActivityId const & activityId)
{
    ErrorCode rejectError;
    if (error.IsError(ErrorCodeValue::RoutingNodeDoesNotMatchFault))
    {
        rejectError = ErrorCodeValue::RoutingError;
    }
    else if (error.IsError(ErrorCodeValue::P2PNodeDoesNotMatchFault))
    {
        rejectError = ErrorCodeValue::P2PError;
    }
    else
    {
        rejectError = error;
    }

    InternalReject(rejectError, activityId);
}
예제 #5
0
ErrorCode SharableProxy::OnAcquire(__inout NodeConfig & ownerConfig,
    Common::TimeSpan ttl,
    bool preempt,
    __out VoteOwnerState & state)
{
    DateTime now;
    ErrorCode error = GetProxyTime(now);
    if (!error.IsSuccess())
    {
        return error;
    }

    ILocalStore::TransactionSPtr trans;
    error = store_->CreateTransaction(trans);
    if (!error.IsSuccess())
    {
        return error;
    }

    VoteOwnerData ownerData;
    wstring key;
    _int64 sequenceNumber;
    error = GetVoteOwnerData(trans, ownerData, sequenceNumber);
    bool dataFound = !error.IsError(ErrorCodeValue::EnumerationCompleted);

    if (dataFound && !error.IsSuccess())
    {
        return error;
    }

    if (!preempt && dataFound)
    {
        VoteProxy::WriteInfo("Acquire", "Owner [{0},{1}] seen at time {2} at {3} for {4}",
            ownerData.Config, ownerData.ExpiryTime, now, ProxyId, VoteId);
        if (ownerData.Id != ownerConfig.Id && ownerData.ExpiryTime > now)
        {
            ownerConfig = NodeConfig(ownerData.Config);
            return ErrorCodeValue::OwnerExists;
        }
    }

    VoteOwnerData newOwnerData(ownerConfig, now + ttl, ownerData.GlobalTicketExpiryTime, ownerData.SuperTicketExpiryTime);
    error = SetVoteOwnerData(newOwnerData, trans, dataFound ? sequenceNumber : -1);
    if (!error.IsSuccess())
    {
        return error;
    }

    state.GlobalTicket = ownerData.GlobalTicketExpiryTime;
    state.SuperTicket = ownerData.SuperTicketExpiryTime;

    return trans->Commit();
}
 bool EntreeService::SendToNodeOperation::IsRetryable(ErrorCode const & error)
 {
     //
     // Queries addressed to components in specific nodes need exact routing(eg: RA, Hosting), fail when
     // node doesnt match exactly. This provides specific error code to user when the node name passed in
     // is not valid.
     //
     if (error.IsError(ErrorCodeValue::RoutingNodeDoesNotMatchFault))
     {
         return false;
     }
     else
     {
         return NamingErrorCategories::IsRetryableAtGateway(error);
     }
 }
ErrorCode ReportUpgradeHealthAsyncOperation::EndAcceptRequest(AsyncOperationSPtr const & operation)
{
    ErrorCode error = this->Replica.EndAcceptReportUpgradeHealth(operation);

    // Upgrade context may be enqueued
    if (error.IsError(ErrorCodeValue::CMRequestAlreadyProcessing))
    {
        error = ErrorCodeValue::Success;
    }

    if (error.IsSuccess())
    {
        this->TryComplete(operation->Parent, error);
    }

    return error;
}
ErrorCode FileStoreServiceReplica::GetServiceLocationSequenceNumber(__out int64 & sequenceNumber)
{
    ErrorCode error;
    ManualResetEvent operationDone;

    propertyManagmentClient_->BeginGetPropertyMetadata(
        NamingUri(serviceName_),
        this->PartitionId.ToString(),
        FileStoreServiceConfig::GetConfig().NamingOperationTimeout,
        [this, &error, &operationDone, &sequenceNumber] (AsyncOperationSPtr const & operation)
    {
        NamePropertyMetadataResult metadataResult;
        error = propertyManagmentClient_->EndGetPropertyMetadata(operation, metadataResult);
        WriteInfo(
            TraceComponent,
            this->TraceId,
            "GetServiceLocationSequenceNumber: SequenceNumber:{0}, Error:{1}",            
            metadataResult.SequenceNumber,
            error);

        if(error.IsSuccess())
        {
            sequenceNumber = metadataResult.SequenceNumber;
        }
        else
        {
            // If the property is not found, then complete with success
            if(error.IsError(ErrorCodeValue::PropertyNotFound))
            {
                // -1 indicates that sequence check should not be done
                sequenceNumber = -1;
                error = ErrorCodeValue::Success;
            }
        }

        operationDone.Set();
    },
        this->CreateAsyncOperationRoot());

    operationDone.WaitOne();

    return error;
}
예제 #9
0
ErrorCode SharableProxy::AribtrateAsyncOperation::GetRecords(
    Store::ILocalStore::TransactionSPtr const & trans,
    LeaseWrapper::LeaseAgentInstance const & instance,
    RecordVector & records)
{
    ILocalStore::EnumerationSPtr enumPtr;
    ErrorCode error = store_->CreateEnumerationByTypeAndKey(trans, ArbitrationRecordType, instance.Id, enumPtr);

    if (error.IsSuccess())
    {
        error = enumPtr->MoveNext();
    }

    if (error.IsSuccess())
    {
        vector<byte> bytes;
        bytes.reserve(4096);
        if (!(error = enumPtr->CurrentValue(bytes)).IsSuccess())
        {
            return error;
        }

        error = FabricSerializer::Deserialize(records, static_cast<ULONG>(bytes.size()), bytes.data());

        if (error.IsSuccess())
        {
            records.PostRead();

            if (records.Instance < instance.InstanceId)
            {
                records.Reset(instance.InstanceId);
            }
        }
    }
    else if (error.IsError(ErrorCodeValue::EnumerationCompleted))
    {
        error = ErrorCode::Success();
    }

    return error;
}
void ReplicasUpdateOperation::ProcessReplica(
    ReplicasUpdateOperationSPtr const & thisSPtr,
    FailoverManager & failoverManager,
    FailoverUnitInfo && failoverUnitInfo,
    bool isDropped)
{
    failoverManager.FTEvents.FTReplicaUpdateReceive(failoverUnitInfo.FailoverUnitDescription.FailoverUnitId.Guid, failoverUnitInfo, isDropped);

    ASSERT_IF(
        failoverManager.IsMaster != (failoverUnitInfo.FailoverUnitDescription.FailoverUnitId.Guid == Constants::FMServiceGuid),
        "Invalid FailoverUnit in ReplicaUp: {0}", failoverUnitInfo);

    auto serviceInfo = failoverManager.ServiceCacheObj.GetService(failoverUnitInfo.ServiceDescription.Name);
    if (serviceInfo)
    {
        if (serviceInfo->ServiceDescription.Instance > failoverUnitInfo.ServiceDescription.Instance)
        {
            failoverManager.WriteInfo(
                "ReplicaUpdate", wformatString(failoverUnitInfo.FailoverUnitDescription.FailoverUnitId),
                "Ignoring report for {0} as a newer version of the service exists.\r\nExisting: {1}\r\nIncoming: {2}",
                failoverUnitInfo.FailoverUnitDescription.FailoverUnitId, serviceInfo->ServiceDescription, failoverUnitInfo.ServiceDescription);

            AddResult(failoverManager, move(failoverUnitInfo), true);
            return;
        }
        else if (serviceInfo->ServiceDescription.Instance == failoverUnitInfo.ServiceDescription.Instance &&
                 serviceInfo->ServiceDescription.UpdateVersion < failoverUnitInfo.ServiceDescription.UpdateVersion)
        {
            ServiceDescription serviceDescription = failoverUnitInfo.ServiceDescription;
            ErrorCode error = failoverManager.ServiceCacheObj.UpdateService(move(serviceDescription));
            if (!error.IsSuccess())
            {
                AddRetry(failoverManager, move(failoverUnitInfo));
                return;
            }
        }
    }

    if (isDropped)
    {
        if (failoverUnitInfo.LocalReplica.IsUp || !failoverUnitInfo.LocalReplica.IsDropped)
        {
            TRACE_AND_TESTASSERT(
                failoverManager.WriteError,
                "ReplicaUpdate", wformatString(failoverUnitInfo.FailoverUnitDescription.FailoverUnitId),
                "Invalid Dropped replica from {0}: {1}", from_, failoverUnitInfo);

            return;
        }
    }

    FailoverUnitId failoverUnitId = failoverUnitInfo.FailoverUnitDescription.FailoverUnitId;
    ReplicaUpdateTask* pTask = new ReplicaUpdateTask(thisSPtr, failoverManager, move(failoverUnitInfo), isDropped, from_); 
    DynamicStateMachineTaskUPtr task(pTask);

    while (task)
    {
        bool result = failoverManager.FailoverUnitCacheObj.TryProcessTaskAsync(failoverUnitId, task, from_, false);
        if (!result)
        {
            ErrorCode error = pTask->ProcessMissingFailoverUnit();
            if (!error.IsError(ErrorCodeValue::FMFailoverUnitAlreadyExists))
            {
                if (!error.IsSuccess())
                {
                    SetError(error, failoverManager, failoverUnitId);
                }

                task = nullptr;
            }
        }
    }
}
    void RemoveServiceAtNameOwnerAsyncOperation::StartRemoveService(AsyncOperationSPtr const & thisSPtr)
    {
        TransactionSPtr txSPtr;
        ErrorCode error = store_.CreateTransaction(this->ActivityHeader, txSPtr);

        if (!error.IsSuccess())
        {
            this->TryComplete(thisSPtr, error);
            return;
        }

        auto nameString = name_.ToString();

        NameData nameData;
        _int64 nameSequenceNumber = -1;

        error = store_.TryReadData(
            txSPtr,
            Constants::NonHierarchyNameEntryType, 
            nameString,
            nameData,
            nameSequenceNumber);

        if (!error.IsSuccess())
        {
            WriteInfo(
                TraceComponent,
                "{0} cannot read name {1} for delete service: error = {2}",
                this->TraceId,
                name_,
                error);

            if (error.IsError(ErrorCodeValue::NotFound))
            {
                error = ErrorCodeValue::NameNotFound;
            }
        }

        if (error.IsSuccess() &&  nameData.ServiceState == UserServiceState::None)
        {
            WriteInfo(
                TraceComponent,
                "{0} user service not found at name owner for {1}",
                this->TraceId,
                name_);

            error = ErrorCodeValue::UserServiceNotFound;
        }

        if (error.IsSuccess())
        {
            if (!isDeletionComplete_)
            {
                if (UserServiceState::IsDeleting(nameData.ServiceState))
                {
                    // Optimization: dont' re-write tentative state
                    NamingStore::CommitReadOnly(move(txSPtr));
                    this->TryComplete(thisSPtr, ErrorCodeValue::Success);
                    return;
                }
                else
                {
                    nameData.ServiceState = UserServiceState::Deleting;
                }
            }
            else
            {
                nameData.ServiceState = UserServiceState::None;
            }

            error = store_.TryWriteData<NameData>(
                txSPtr,
                nameData,
                Constants::NonHierarchyNameEntryType,
                nameString,
                nameSequenceNumber);
        }

        if (error.IsSuccess() && isDeletionComplete_)
        {
            wstring const & storeType = Constants::UserServiceDataType;
            _int64 psdSequenceNumber = -1;

            error = store_.TryGetCurrentSequenceNumber(txSPtr, storeType, nameString, psdSequenceNumber);

            if (error.IsSuccess())
            {
                error = store_.DeleteFromStore(txSPtr, storeType, nameString, psdSequenceNumber);
            }
            else if (error.IsError(ErrorCodeValue::NotFound))
            {
                error = ErrorCodeValue::Success;
            }
        }

        if (error.IsSuccess())
        {
            auto operation = NamingStore::BeginCommit(
                move(txSPtr),
                timeoutHelper_.GetRemainingTime(),
                [this](AsyncOperationSPtr const & operation) { this->OnCommitComplete(operation, false); },
                thisSPtr);
            this->OnCommitComplete(operation, true);
        }
        else
        {
            txSPtr.reset();
            this->TryComplete(thisSPtr, error);
        }
    }
예제 #12
0
ErrorCode SecurityUser::SetupGroupMembershipForNewUser()
{
    ErrorCode error = SecurityPrincipalHelper::AddMemberToLocalGroup(FabricConstants::WindowsFabricAllowedUsersGroupName, AccountName);

    ASSERT_IF(error.IsError(ErrorCodeValue::AlreadyExists) && 
        AccountType == SecurityPrincipalAccountType::LocalUser,
        "AddMemberToLocalGroup cannot return AlreadyExists after a new account was created");

    if (!error.IsSuccess() &&
        !error.IsError(ErrorCodeValue::AlreadyExists))
    {
        return error;
    }

    error = BufferedSid::CreateSPtr(AccountName, sid_);
    if (!error.IsSuccess())
    {
        return error;
    }

    // Add the user to the desired groups
    for (auto it = parentApplicationGroups_.begin(); it != parentApplicationGroups_.end(); ++it)
    {
        // The group should have been created previously
        // by the app environment manager
        error = SecurityPrincipalHelper::AddMemberToLocalGroup(
            *it /*parentGroup*/, 
            AccountName /*memberToAdd*/);
        if (!error.IsSuccess() &&
            !error.IsError(ErrorCodeValue::AlreadyExists))
        {
            return error;
        }
    }

    for (auto it = parentSystemGroups_.begin(); it != parentSystemGroups_.end(); ++it)
    {
        if(AccountHelper::GroupAllowsMemberAddition(*it))
        {
            error = SecurityPrincipalHelper::AddMemberToLocalGroup(
                *it /*parentGroup*/, 
                AccountName /*memberToAdd*/);
            if (!error.IsSuccess() &&
                !error.IsError(ErrorCodeValue::AlreadyExists))
            {
                return error;
            }
        }
        else
        {
            WriteInfo(
                TraceSecurityUser,
                "Skip adding account {0} to group {1} since members cannot be added",
                AccountName,
                *it);
            error = BufferedSid::CreateSPtr(WinLocalSid, sidToAdd_);
            if(!error.IsSuccess())
            {
                return error;
            }
        }
    }
    return ErrorCode(ErrorCodeValue::Success);
}