protected Task ScheduleJobAsync(CancellationToken cancellation = default) { _logger.LogInformation($"Scheduling job '{_jobName}' with schedule '{_schedule}'"); var from = _useLocalTimeZone ? DateTimeOffset.Now : DateTimeOffset.UtcNow; var next = _cronExpression.GetNextOccurrence(from, _timeZone); if (next.HasValue) { _logger.LogInformation($"Job '{_jobName}' estimated next execution time is '{next.Value}'"); var delay = next.Value - DateTimeOffset.Now; _timer = new Timer(delay.TotalMilliseconds); _timer.Elapsed += async(sender, args) => { // Clean-up _timer.Dispose(); _timer = null; if (cancellation.IsCancellationRequested) { return; } try { _logger.LogInformation($"Starting execution of job '{_jobName}'"); using (await ResourceLocker.LockAsync(_jobFullName, cancellation)) using (var scope = _serviceProvider.CreateScope()) { var job = scope.ServiceProvider.GetRequiredService <TJob>(); await job.ExecuteAsync(cancellation); } _logger.LogInformation($"Job '{_jobName}' executed successfully"); } catch (Exception e) { _logger.LogError(e, $"Job '{_jobName}' execution failed with exception"); } finally { if (!cancellation.IsCancellationRequested) { await ScheduleJobAsync(cancellation); } } }; _timer.Start(); } return(Task.CompletedTask); }
/// <summary> /// Deletes a relationship by its id, returning its properties which are now /// removed. It is assumed that the nodes it connects have already been /// deleted in this /// transaction. /// </summary> /// <param name="id"> The id of the relationship to delete. </param> internal virtual void RelDelete(long id, RecordAccessSet recordChanges, ResourceLocker locks) { RelationshipRecord record = recordChanges.RelRecords.getOrLoad(id, null).forChangingLinkage(); _propertyChainDeleter.deletePropertyChain(record, recordChanges.PropertyRecords); DisconnectRelationship(record, recordChanges, locks); UpdateNodesForDeletedRelationship(record, recordChanges, locks); record.InUse = false; }
public TezosAccount( ICurrencies currencies, IHdWallet wallet, IAccountDataRepository dataRepository) : base(TezosConfig.Xtz, currencies, wallet, dataRepository) { var xtz = Config; _tezosRevealChecker = new TezosRevealChecker(xtz); _tezosAllocationChecker = new TezosAllocationChecker(xtz); AddressLocker = new ResourceLocker <string>(); }
internal TransactionRecordState(NeoStores neoStores, IntegrityValidator integrityValidator, RecordChangeSet recordChangeSet, long lastCommittedTxWhenTransactionStarted, ResourceLocker locks, RelationshipCreator relationshipCreator, RelationshipDeleter relationshipDeleter, PropertyCreator propertyCreator, PropertyDeleter propertyDeleter) { this._neoStores = neoStores; this._nodeStore = neoStores.NodeStore; this._relationshipStore = neoStores.RelationshipStore; this._propertyStore = neoStores.PropertyStore; this._relationshipGroupStore = neoStores.RelationshipGroupStore; this._metaDataStore = neoStores.MetaDataStore; this._schemaStore = neoStores.SchemaStore; this._integrityValidator = integrityValidator; this._recordChangeSet = recordChangeSet; this._lastCommittedTxWhenTransactionStarted = lastCommittedTxWhenTransactionStarted; this._locks = locks; this._relationshipCreator = relationshipCreator; this._relationshipDeleter = relationshipDeleter; this._propertyCreator = propertyCreator; this._propertyDeleter = propertyDeleter; }
private void DecrementTotalRelationshipCount(long nodeId, RelationshipRecord rel, long firstRelId, RecordAccess <RelationshipRecord, Void> relRecords, ResourceLocker locks) { if (firstRelId == Record.NO_PREV_RELATIONSHIP.intValue()) { return; } bool firstInChain = RelIsFirstInChain(nodeId, rel); if (!firstInChain) { locks.AcquireExclusive(LockTracer.NONE, ResourceTypes.RELATIONSHIP, firstRelId); } RelationshipRecord firstRel = relRecords.GetOrLoad(firstRelId, null).forChangingLinkage(); if (nodeId == firstRel.FirstNode) { firstRel.FirstPrevRel = firstInChain ? relCount(nodeId, rel) - 1 : relCount(nodeId, firstRel) - 1; firstRel.FirstInFirstChain = true; } if (nodeId == firstRel.SecondNode) { firstRel.SecondPrevRel = firstInChain ? relCount(nodeId, rel) - 1 : relCount(nodeId, firstRel) - 1; firstRel.FirstInSecondChain = true; } }
private void UpdateNodesForDeletedRelationship(RelationshipRecord rel, RecordAccessSet recordChanges, ResourceLocker locks) { RecordAccess_RecordProxy <NodeRecord, Void> startNodeChange = recordChanges.NodeRecords.getOrLoad(rel.FirstNode, null); RecordAccess_RecordProxy <NodeRecord, Void> endNodeChange = recordChanges.NodeRecords.getOrLoad(rel.SecondNode, null); NodeRecord startNode = recordChanges.NodeRecords.getOrLoad(rel.FirstNode, null).forReadingLinkage(); NodeRecord endNode = recordChanges.NodeRecords.getOrLoad(rel.SecondNode, null).forReadingLinkage(); bool loop = startNode.Id == endNode.Id; if (!startNode.Dense) { if (rel.FirstInFirstChain) { startNode = startNodeChange.ForChangingLinkage(); startNode.NextRel = rel.FirstNextRel; } DecrementTotalRelationshipCount(startNode.Id, rel, startNode.NextRel, recordChanges.RelRecords, locks); } else { RecordAccess_RecordProxy <RelationshipGroupRecord, int> groupChange = _relGroupGetter.getRelationshipGroup(startNode, rel.Type, recordChanges.RelGroupRecords).group(); Debug.Assert(groupChange != null, "Relationship group " + rel.Type + " should have existed here"); RelationshipGroupRecord group = groupChange.ForReadingData(); DirectionWrapper dir = DirectionIdentifier.wrapDirection(rel, startNode); if (rel.FirstInFirstChain) { group = groupChange.ForChangingData(); dir.setNextRel(group, rel.FirstNextRel); if (GroupIsEmpty(group)) { DeleteGroup(startNodeChange, group, recordChanges.RelGroupRecords); } } DecrementTotalRelationshipCount(startNode.Id, rel, dir.getNextRel(group), recordChanges.RelRecords, locks); } if (!endNode.Dense) { if (rel.FirstInSecondChain) { endNode = endNodeChange.ForChangingLinkage(); endNode.NextRel = rel.SecondNextRel; } if (!loop) { DecrementTotalRelationshipCount(endNode.Id, rel, endNode.NextRel, recordChanges.RelRecords, locks); } } else { RecordAccess_RecordProxy <RelationshipGroupRecord, int> groupChange = _relGroupGetter.getRelationshipGroup(endNode, rel.Type, recordChanges.RelGroupRecords).group(); DirectionWrapper dir = DirectionIdentifier.wrapDirection(rel, endNode); Debug.Assert(groupChange != null || loop, "Group has been deleted"); if (groupChange != null) { RelationshipGroupRecord group; if (rel.FirstInSecondChain) { group = groupChange.ForChangingData(); dir.setNextRel(group, rel.SecondNextRel); if (GroupIsEmpty(group)) { DeleteGroup(endNodeChange, group, recordChanges.RelGroupRecords); } } } // Else this is a loop-rel and the group was deleted when dealing with the start node if (!loop) { DecrementTotalRelationshipCount(endNode.Id, rel, dir.getNextRel(groupChange.ForChangingData()), recordChanges.RelRecords, locks); } } }
private void ConvertNodeToDenseIfNecessary(NodeRecord node, RecordAccess <RelationshipRecord, Void> relRecords, RecordAccess <RelationshipGroupRecord, int> relGroupRecords, ResourceLocker locks) { if (node.Dense) { return; } long relId = node.NextRel; if (relId != Record.NO_NEXT_RELATIONSHIP.intValue()) { RecordAccess_RecordProxy <RelationshipRecord, Void> relChange = relRecords.GetOrLoad(relId, null); RelationshipRecord rel = relChange.ForReadingLinkage(); if (RelCount(node.Id, rel) >= _denseNodeThreshold) { locks.AcquireExclusive(LockTracer.NONE, ResourceTypes.RELATIONSHIP, relId); // Re-read the record after we've locked it since another transaction might have // changed in the meantime. relChange = relRecords.GetOrLoad(relId, null); ConvertNodeToDenseNode(node, relChange.ForChangingLinkage(), relRecords, relGroupRecords, locks); } } }
public ClientValidationRuleTranslatorPluginFacadeImpl() { _resourceLocker = new ResourceLocker <Resources>(new Resources { Owner = this }, Resources.Initialize); }
public WorkflowRuntimeProviderPluginFacadeImpl() { _resources = new ResourceLocker <Resources>(new Resources { Owner = this }, Resources.Initialize); }
private void ConvertNodeToDenseNode(NodeRecord node, RelationshipRecord firstRel, RecordAccess <RelationshipRecord, Void> relRecords, RecordAccess <RelationshipGroupRecord, int> relGroupRecords, ResourceLocker locks) { node.Dense = true; node.NextRel = Record.NO_NEXT_RELATIONSHIP.intValue(); long relId = firstRel.Id; RelationshipRecord relRecord = firstRel; while (relId != Record.NO_NEXT_RELATIONSHIP.intValue()) { // Get the next relationship id before connecting it (where linkage is overwritten) relId = RelChain(relRecord, node.Id).get(relRecord); ConnectRelationshipToDenseNode(node, relRecord, relRecords, relGroupRecords, locks); if (relId != Record.NO_NEXT_RELATIONSHIP.intValue()) { // Lock and load the next relationship in the chain locks.AcquireExclusive(LockTracer.NONE, ResourceTypes.RELATIONSHIP, relId); relRecord = relRecords.GetOrLoad(relId, null).forChangingLinkage(); } } }
private void Connect(NodeRecord node, RelationshipRecord rel, RecordAccess <RelationshipRecord, Void> relRecords, ResourceLocker locks) { Connect(node.Id, node.NextRel, rel, relRecords, locks); }
private void ConnectRelationshipToDenseNode(NodeRecord node, RelationshipRecord rel, RecordAccess <RelationshipRecord, Void> relRecords, RecordAccess <RelationshipGroupRecord, int> relGroupRecords, ResourceLocker locks) { RelationshipGroupRecord group = _relGroupGetter.getOrCreateRelationshipGroup(node, rel.Type, relGroupRecords).forChangingData(); DirectionWrapper dir = DirectionIdentifier.wrapDirection(rel, node); long nextRel = dir.getNextRel(group); SetCorrectNextRel(node, rel, nextRel); Connect(node.Id, nextRel, rel, relRecords, locks); dir.setNextRel(group, rel.Id); }
private void ConnectRelationship(NodeRecord firstNode, NodeRecord secondNode, RelationshipRecord rel, RecordAccess <RelationshipRecord, Void> relRecords, RecordAccess <RelationshipGroupRecord, int> relGroupRecords, ResourceLocker locks) { // Assertion interpreted: if node is a normal node and we're trying to create a // relationship that we already have as first rel for that node --> error Debug.Assert(firstNode.NextRel != rel.Id || firstNode.Dense); Debug.Assert(secondNode.NextRel != rel.Id || secondNode.Dense); if (!firstNode.Dense) { rel.FirstNextRel = firstNode.NextRel; } if (!secondNode.Dense) { rel.SecondNextRel = secondNode.NextRel; } if (!firstNode.Dense) { Connect(firstNode, rel, relRecords, locks); } else { ConnectRelationshipToDenseNode(firstNode, rel, relRecords, relGroupRecords, locks); } if (!secondNode.Dense) { if (firstNode.Id != secondNode.Id) { Connect(secondNode, rel, relRecords, locks); } else { rel.FirstInFirstChain = true; rel.SecondPrevRel = rel.FirstPrevRel; } } else if (firstNode.Id != secondNode.Id) { ConnectRelationshipToDenseNode(secondNode, rel, relRecords, relGroupRecords, locks); } if (!firstNode.Dense) { firstNode.NextRel = rel.Id; } if (!secondNode.Dense) { secondNode.NextRel = rel.Id; } }
public ClientValidationRuleTranslatorPluginFacadeImpl() { _resourceLocker = new ResourceLocker<Resources>(new Resources { Owner = this }, Resources.Initialize); }
private void DisconnectRelationship(RelationshipRecord rel, RecordAccessSet recordChangeSet, ResourceLocker locks) { Disconnect(rel, RelationshipConnection.StartNext, recordChangeSet.RelRecords, locks); Disconnect(rel, RelationshipConnection.StartPrev, recordChangeSet.RelRecords, locks); Disconnect(rel, RelationshipConnection.EndNext, recordChangeSet.RelRecords, locks); Disconnect(rel, RelationshipConnection.EndPrev, recordChangeSet.RelRecords, locks); }
private void Connect(long nodeId, long firstRelId, RelationshipRecord rel, RecordAccess <RelationshipRecord, Void> relRecords, ResourceLocker locks) { long newCount = 1; if (firstRelId != Record.NO_NEXT_RELATIONSHIP.intValue()) { locks.AcquireExclusive(LockTracer.NONE, ResourceTypes.RELATIONSHIP, firstRelId); RelationshipRecord firstRel = relRecords.GetOrLoad(firstRelId, null).forChangingLinkage(); bool changed = false; if (firstRel.FirstNode == nodeId) { newCount = firstRel.FirstPrevRel + 1; firstRel.FirstPrevRel = rel.Id; firstRel.FirstInFirstChain = false; changed = true; } if (firstRel.SecondNode == nodeId) { newCount = firstRel.SecondPrevRel + 1; firstRel.SecondPrevRel = rel.Id; firstRel.FirstInSecondChain = false; changed = true; } if (!changed) { throw new InvalidRecordException(nodeId + " doesn't match " + firstRel); } } // Set the relationship count if (rel.FirstNode == nodeId) { rel.FirstPrevRel = newCount; rel.FirstInFirstChain = true; } if (rel.SecondNode == nodeId) { rel.SecondPrevRel = newCount; rel.FirstInSecondChain = true; } }
private void Disconnect(RelationshipRecord rel, RelationshipConnection pointer, RecordAccess <RelationshipRecord, Void> relChanges, ResourceLocker locks) { long otherRelId = pointer.otherSide().get(rel); if (otherRelId == Record.NO_NEXT_RELATIONSHIP.intValue()) { return; } locks.AcquireExclusive(LockTracer.NONE, ResourceTypes.RELATIONSHIP, otherRelId); RelationshipRecord otherRel = relChanges.GetOrLoad(otherRelId, null).forChangingLinkage(); bool changed = false; long newId = pointer.get(rel); bool newIsFirst = pointer.isFirstInChain(rel); if (otherRel.FirstNode == pointer.compareNode(rel)) { pointer.start().set(otherRel, newId, newIsFirst); changed = true; } if (otherRel.SecondNode == pointer.compareNode(rel)) { pointer.end().set(otherRel, newId, newIsFirst); changed = true; } if (!changed) { throw new InvalidRecordException(otherRel + " don't match " + rel); } }
/// <summary> /// Creates a relationship with the given id, from the nodes identified by id /// and of type typeId /// </summary> /// <param name="id"> The id of the relationship to create. </param> /// <param name="type"> The id of the relationship type this relationship will /// have. </param> /// <param name="firstNodeId"> The id of the start node. </param> /// <param name="secondNodeId"> The id of the end node. </param> public virtual void RelationshipCreate(long id, int type, long firstNodeId, long secondNodeId, RecordAccessSet recordChangeSet, ResourceLocker locks) { // TODO could be unnecessary to mark as changed here already, dense nodes may not need to change NodeRecord firstNode = recordChangeSet.NodeRecords.getOrLoad(firstNodeId, null).forChangingLinkage(); NodeRecord secondNode = recordChangeSet.NodeRecords.getOrLoad(secondNodeId, null).forChangingLinkage(); ConvertNodeToDenseIfNecessary(firstNode, recordChangeSet.RelRecords, recordChangeSet.RelGroupRecords, locks); ConvertNodeToDenseIfNecessary(secondNode, recordChangeSet.RelRecords, recordChangeSet.RelGroupRecords, locks); RelationshipRecord record = recordChangeSet.RelRecords.create(id, null).forChangingLinkage(); record.SetLinks(firstNodeId, secondNodeId, type); record.InUse = true; record.SetCreated(); ConnectRelationship(firstNode, secondNode, record, recordChangeSet.RelRecords, recordChangeSet.RelGroupRecords, locks); }
public WorkflowRuntimeProviderPluginFacadeImpl() { _resources = new ResourceLocker<Resources>(new Resources { Owner = this }, Resources.Initialize); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("resource") @Override public void createCommands(java.util.Collection<org.neo4j.storageengine.api.StorageCommand> commands, org.neo4j.storageengine.api.txstate.ReadableTransactionState txState, org.neo4j.storageengine.api.StorageReader storageReader, org.neo4j.storageengine.api.lock.ResourceLocker locks, long lastTransactionIdWhenStarted, org.neo4j.storageengine.api.txstate.TxStateVisitor_Decorator additionalTxStateVisitor) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException, org.neo4j.internal.kernel.api.exceptions.schema.CreateConstraintFailureException, org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public override void CreateCommands(ICollection <StorageCommand> commands, ReadableTransactionState txState, StorageReader storageReader, ResourceLocker locks, long lastTransactionIdWhenStarted, Org.Neo4j.Storageengine.Api.txstate.TxStateVisitor_Decorator additionalTxStateVisitor) { if (txState != null) { // We can make this cast here because we expected that the storageReader passed in here comes from // this storage engine itself, anything else is considered a bug. And we do know the inner workings // of the storage statements that we create. RecordStorageCommandCreationContext creationContext = (( RecordStorageReader )storageReader).CommandCreationContext; TransactionRecordState recordState = creationContext.CreateTransactionRecordState(_integrityValidator, lastTransactionIdWhenStarted, locks); // Visit transaction state and populate these record state objects TxStateVisitor txStateVisitor = new TransactionToRecordStateVisitor(recordState, _schemaState, _schemaStorage, _constraintSemantics); CountsRecordState countsRecordState = new CountsRecordState(); txStateVisitor = additionalTxStateVisitor.apply(txStateVisitor); txStateVisitor = new TransactionCountingStateVisitor(txStateVisitor, storageReader, txState, countsRecordState); using (TxStateVisitor visitor = txStateVisitor) { txState.Accept(visitor); } // Convert record state into commands recordState.ExtractCommands(commands); countsRecordState.ExtractCommands(commands); } }