/// <summary> /// Creates a new generator with only a single sequence schema. /// </summary> /// <param name="store"></param> /// <param name="sequence"></param> public SequenceIdGenerator(ISequenceIdOptimisticSyncStore store, SequenceIdStore sequence) { _store = store; _sequences = new Dictionary <string, SequenceIdStore> { { sequence.Schema.TableName, sequence } }; }
private void RenewCachedIds(SequenceIdStore sequence) { //sequence is already locked during this call from calling method. int retryCount = 0; while (retryCount < MaxSyncRetries + 1) { try { if (retryCount == 0 && String.IsNullOrWhiteSpace(sequence.LastId)) { _store.InsertOrUpdate(sequence.Schema); } var syncData = _store.GetData(sequence.Schema.TableName); var lastStoredId = syncData.Data; syncData.Data = syncData.Data.LexicalAdd(sequence.CharacterSet, _ignoreCase, sequence.Schema.RangeSize); if (_store.TryWrite(syncData)) { sequence.LastId = lastStoredId; //next id used will increment from here. sequence.FinalCachedId = syncData.Data; return; } } catch (Exception aex) { LogProvider.WarnFormat("Failed to RenewCachedIds for table '{0}' on attempt {1} of {2}", aex, sequence.Schema.TableName, retryCount, MaxSyncRetries); if (retryCount == MaxSyncRetries) { throw; } } retryCount++; } LogProvider.ErrorFormat("Failed to update the OptimisticSyncStore for table '{0}' after {1} attempts. RangeSize: {2}.", sequence.Schema.TableName, retryCount, sequence.Schema.RangeSize); throw new ApplicationException(String.Format( "Failed to update the OptimisticSyncStore for table '{0}' after {1} attempts. RangeSize: {2}.", sequence.Schema.TableName, retryCount, sequence.Schema.RangeSize)); }
/// <summary> /// Creates a new generator with only a single sequence schema. /// </summary> /// <param name="store"></param> /// <param name="sequence"></param> public SequenceIdGenerator(ISequenceIdOptimisticSyncStore store, SequenceIdStore sequence) { _store = store; _sequences = new Dictionary<string, SequenceIdStore> {{sequence.Schema.TableName, sequence}}; }
private void RenewCachedIds(SequenceIdStore sequence) { //sequence is already locked during this call from calling method. int retryCount = 0; while (retryCount < MaxSyncRetries + 1) { try { if (retryCount == 0 && String.IsNullOrWhiteSpace(sequence.LastId)) _store.InsertOrUpdate(sequence.Schema); var syncData = _store.GetData(sequence.Schema.TableName); var lastStoredId = syncData.Data; syncData.Data = syncData.Data.LexicalAdd(sequence.CharacterSet, _ignoreCase, sequence.Schema.RangeSize); if (_store.TryWrite(syncData)) { sequence.LastId = lastStoredId; //next id used will increment from here. sequence.FinalCachedId = syncData.Data; return; } } catch (Exception aex) { LogProvider.WarnFormat("Failed to RenewCachedIds for table '{0}' on attempt {1} of {2}", aex, sequence.Schema.TableName, retryCount, MaxSyncRetries); if (retryCount == MaxSyncRetries) throw; } retryCount++; } LogProvider.ErrorFormat("Failed to update the OptimisticSyncStore for table '{0}' after {1} attempts. RangeSize: {2}.", sequence.Schema.TableName, retryCount, sequence.Schema.RangeSize); throw new ApplicationException(String.Format( "Failed to update the OptimisticSyncStore for table '{0}' after {1} attempts. RangeSize: {2}.", sequence.Schema.TableName, retryCount, sequence.Schema.RangeSize)); }