/// <summary> /// replication thread function. /// note: While replicating operations, a dummy '0' sequence id is passed. /// this sequence id is totally ignored by asynchronous POR, but we are keeping it /// to maintain the symmetry in API. /// </summary> public void Run() { //reload threshold value from service config, consider the probability that values would have been changed by user _bulkKeysToReplicate = ServiceConfiguration.BulkItemsToReplicate; IList opCodesToBeReplicated = new ClusteredArrayList(_bulkKeysToReplicate); IList infoToBeReplicated = new ClusteredArrayList(_bulkKeysToReplicate); IList compilationInfo = new ClusteredArrayList(_bulkKeysToReplicate); IList userPayLoad = new ClusteredArrayList(); try { while (!stopped || _queue.Count > 0) { DateTime startedAt = DateTime.Now; DateTime finishedAt = DateTime.Now; try { for (int i = 0; _queue.Count > 0 && i < _bulkKeysToReplicate; i++) { IOptimizedQueueOperation operation = null; operation = _queue.Dequeue(); DictionaryEntry entry = (DictionaryEntry)operation.Data; opCodesToBeReplicated.Add(entry.Key); infoToBeReplicated.Add(entry.Value); if (operation.UserPayLoad != null) { if (userPayLoad == null) { userPayLoad = new ArrayList(); } for (int j = 0; j < operation.UserPayLoad.Length; j++) { userPayLoad.Add(operation.UserPayLoad.GetValue(j)); } } compilationInfo.Add(operation.PayLoadSize); } object[] updateIndexKeys = GetIndexOperations(); if (!stopped) { if (opCodesToBeReplicated.Count > 0 || updateIndexKeys != null) { if (updateIndexKeys != null) { opCodesToBeReplicated.Add((int)ClusterCacheBase.OpCodes.UpdateIndice); infoToBeReplicated.Add(updateIndexKeys); } _context.CacheImpl.ReplicateOperations(opCodesToBeReplicated, infoToBeReplicated, userPayLoad, compilationInfo, _context.CacheImpl.OperationSequenceId, _context.CacheImpl.CurrentViewId); } } if (!stopped && _context.PerfStatsColl != null) { _context.PerfStatsColl.IncrementMirrorQueueSizeStats(_queue.Count); } } catch (Exception e) { if (e.Message.IndexOf("operation timeout", StringComparison.OrdinalIgnoreCase) >= 0 && !_shutdownStatusLatch.IsAnyBitsSet(ShutDownStatus.SHUTDOWN_INPROGRESS)) { _context.NCacheLog.CriticalInfo("AsyncReplicator.Run", "Bulk operation timeout. Retrying the operation."); try { if (!stopped) { _context.CacheImpl.ReplicateOperations(opCodesToBeReplicated, infoToBeReplicated, userPayLoad, compilationInfo, 0, 0); _context.NCacheLog.CriticalInfo("AsyncReplicator.Run", "RETRY is successfully."); } } catch (Exception ex) { if (_context.NCacheLog.IsErrorEnabled) { _context.NCacheLog.Error("AsyncReplicator.RUN", "Error occurred while retrying operation. " + ex.ToString()); } } } else if (_context.NCacheLog.IsErrorEnabled) { _context.NCacheLog.Error("AsyncReplicator.RUN", e.ToString()); } } finally { opCodesToBeReplicated.Clear(); infoToBeReplicated.Clear(); compilationInfo.Clear(); if (userPayLoad != null) { userPayLoad.Clear(); } finishedAt = DateTime.Now; } if (_queue.Count > 0) { continue; } else if (_queue.Count == 0 && _shutdownStatusLatch.IsAnyBitsSet(ShutDownStatus.SHUTDOWN_INPROGRESS)) { _shutdownStatusLatch.SetStatusBit(ShutDownStatus.SHUTDOWN_COMPLETED, ShutDownStatus.SHUTDOWN_INPROGRESS); return; } if ((finishedAt.Ticks - startedAt.Ticks) < _interval.Ticks) { Thread.Sleep(_interval.Subtract(finishedAt.Subtract(startedAt))); } else { Thread.Sleep(_interval); } } } catch (ThreadAbortException ta) { //_context.CacheTrace.error("AsyncReplicator.RUN", "Async replicator stopped. " + ta.ToString()); } catch (ThreadInterruptedException ti) { //_context.CacheTrace.error("AsyncReplicator.RUN", "Async replicator stopped. " + ti.ToString()); } catch (NullReferenceException) { } catch (Exception e) { if (!stopped) { _context.NCacheLog.Error("AsyncReplicator.RUN", "Async replicator stopped. " + e.ToString()); } } }
/// <summary> /// replication thread function. /// note: While replicating operations, a dummy '0' sequence id is passed. /// this sequence id is totally ignored by asynchronous POR, but we are keeping it /// to maintain the symmetry in API. /// </summary> public void Run() { ArrayList opCodesToBeReplicated = new ArrayList(_bulkKeysToReplicate); ArrayList infoToBeReplicated = new ArrayList(_bulkKeysToReplicate); ArrayList compilationInfo = new ArrayList(_bulkKeysToReplicate); ArrayList userPayLoad = new ArrayList(); try { while (!stopped || _queue.Count > 0) { DateTime startedAt = DateTime.Now; DateTime finishedAt = DateTime.Now; try { for (int i = 0; _queue.Count > 0 && i < _bulkKeysToReplicate; i++) { IOptimizedQueueOperation operation = null; operation = _queue.Dequeue(); DictionaryEntry entry = (DictionaryEntry)operation.Data; opCodesToBeReplicated.Add(entry.Key); infoToBeReplicated.Add(entry.Value); if (operation.UserPayLoad != null) { for (int j = 0; j < operation.UserPayLoad.Length; j++) { userPayLoad.Add(operation.UserPayLoad.GetValue(j)); } } compilationInfo.Add(operation.PayLoadSize); } object[] updateIndexKeys = GetIndexOperations(); if (!stopped) { if (opCodesToBeReplicated.Count > 0 || updateIndexKeys != null) { if (updateIndexKeys != null) { opCodesToBeReplicated.Add((int)ClusterCacheBase.OpCodes.UpdateIndice); infoToBeReplicated.Add(updateIndexKeys); } _context.CacheImpl.ReplicateOperations(opCodesToBeReplicated.ToArray(), infoToBeReplicated.ToArray(), userPayLoad.ToArray(), compilationInfo, _context.CacheImpl.OperationSequenceId, _context.CacheImpl.CurrentViewId); } } if (!stopped && _context.PerfStatsColl != null) { _context.PerfStatsColl.IncrementMirrorQueueSizeStats(_queue.Count); } } catch (Exception e) { if (e.Message.IndexOf("operation timeout", StringComparison.OrdinalIgnoreCase) >= 0) { _context.NCacheLog.CriticalInfo("AsyncReplicator.Run", "Bulk operation timedout. Retrying the operation."); try { if (!stopped) { _context.CacheImpl.ReplicateOperations(opCodesToBeReplicated.ToArray(), infoToBeReplicated.ToArray(), userPayLoad.ToArray(), compilationInfo, 0, 0); _context.NCacheLog.CriticalInfo("AsyncReplicator.Run", "RETRY is successfull."); } } catch (Exception ex) { if (_context.NCacheLog.IsErrorEnabled) { _context.NCacheLog.Error("AsyncReplicator.RUN", "Error occurred while retrying operation. " + ex.ToString()); } } } else if (_context.NCacheLog.IsErrorEnabled) { _context.NCacheLog.Error("AsyncReplicator.RUN", e.ToString()); } } finally { opCodesToBeReplicated.Clear(); infoToBeReplicated.Clear(); compilationInfo.Clear(); userPayLoad.Clear(); finishedAt = DateTime.Now; } if (_queue.Count > 0) { continue; } if ((finishedAt.Ticks - startedAt.Ticks) < _interval.Ticks) { Thread.Sleep(_interval.Subtract(finishedAt.Subtract(startedAt))); } else { Thread.Sleep(_interval); } } } catch (ThreadAbortException ta) { } catch (ThreadInterruptedException ti) { } catch (NullReferenceException) { } catch (Exception e) { if (!stopped) { _context.NCacheLog.Error("AsyncReplicator.RUN", "Async replicator stopped. " + e.ToString()); } } }