/// <summary> /// Adds a pair of key and value to the cache. If the specified key already exists /// in the cache; it is updated, otherwise a new item is added to the cache. /// </summary> /// <param name="key">key of the entry.</param> /// <param name="cacheEntry">the cache entry.</param> /// <returns>returns the result of operation.</returns> internal override CacheInsResult InsertInternal(object key, CacheEntry cacheEntry, bool isUserOperation, CacheEntry oldEntry, OperationContext operationContext, bool updateIndex) { CacheInsResult result = base.InsertInternal(key, cacheEntry, isUserOperation, oldEntry, operationContext, updateIndex); if (result == CacheInsResult.Success || result == CacheInsResult.SuccessNearEvicition) { if (_queryIndexManager != null && cacheEntry.QueryInfo != null) { _queryIndexManager.AddToIndex(key, cacheEntry, operationContext); } } else if ((result == CacheInsResult.SuccessOverwrite || result == CacheInsResult.SuccessOverwriteNearEviction) && updateIndex) { if (_queryIndexManager != null) { if (oldEntry != null && oldEntry.ObjectType != null) { _queryIndexManager.RemoveFromIndex(key, oldEntry); } if (cacheEntry.QueryInfo != null) { _queryIndexManager.AddToIndex(key, cacheEntry, operationContext); } } } if (_context.PerfStatsColl != null && _queryIndexManager != null) { _context.PerfStatsColl.SetQueryIndexSize(_queryIndexManager.IndexInMemorySize); } return(result); }
/// <summary> /// Adds a pair of key and value to the cache. If the specified key already exists /// in the cache; it is updated, otherwise a new item is added to the cache. /// </summary> /// <param name="key">key of the entry.</param> /// <param name="cacheEntry">the cache entry.</param> /// <returns>returns the result of operation.</returns> internal override CacheInsResult InsertInternal(object key, CacheEntry cacheEntry, bool isUserOperation, CacheEntry oldEntry, OperationContext operationContext, bool updateIndex) { if (oldEntry != null) { if (!Util.CacheHelper.CheckDataGroupsCompatibility(cacheEntry.GroupInfo, oldEntry.GroupInfo)) { return(CacheInsResult.IncompatibleGroup);// throw new Exception("Data group of the inserted item does not match the existing item's data group"); } } CacheInsResult result = base.InsertInternal(key, cacheEntry, isUserOperation, oldEntry, operationContext, updateIndex); if (result == CacheInsResult.Success || result == CacheInsResult.SuccessNearEvicition) { _grpIndexManager.AddToGroup(key, cacheEntry.GroupInfo); if (_queryIndexManager != null && cacheEntry.QueryInfo != null) { _queryIndexManager.AddToIndex(key, cacheEntry, operationContext); } } else if ((result == CacheInsResult.SuccessOverwrite || result == CacheInsResult.SuccessOverwriteNearEviction) && updateIndex) { if (oldEntry != null) { _grpIndexManager.RemoveFromGroup(key, oldEntry.GroupInfo); } _grpIndexManager.AddToGroup(key, cacheEntry.GroupInfo); if (_queryIndexManager != null) { if (oldEntry != null && oldEntry.ObjectType != null) { _queryIndexManager.RemoveFromIndex(key, oldEntry); } if (cacheEntry.QueryInfo != null) { _queryIndexManager.AddToIndex(key, cacheEntry, operationContext); } } } if (_context.PerfStatsColl != null) { if (_queryIndexManager != null) { _context.PerfStatsColl.SetQueryIndexSize(_queryIndexManager.IndexInMemorySize); } _context.PerfStatsColl.SetGroupIndexSize(_grpIndexManager.IndexInMemorySize); } return(result); }
internal override CacheInsResult InsertInternal(object key, CacheEntry cacheEntry, bool isUserOperation, CacheEntry oldEntry, OperationContext operationContext) { int bucketId = GetBucketId(key as string); OperationLogger opLogger = null; //muds: //fetch the operation logger... if (_logMgr.IsOperationAllowed(bucketId) && LocalBuckets.Contains(bucketId)) { long oldEntrysize = oldEntry == null ? 0 : oldEntry.DataSize; if (_logMgr.IsLoggingEnbaled(bucketId, LogMode.LogBeforeActualOperation) && isUserOperation) { _logMgr.LogOperation(bucketId, key, cacheEntry, OperationType.Insert); return(oldEntry != null ? CacheInsResult.SuccessOverwrite : CacheInsResult.Success); } CacheEntry clone = (CacheEntry)cacheEntry.Clone(); CacheInsResult result = base.InsertInternal(key, cacheEntry, isUserOperation, oldEntry, operationContext); switch (result) { case CacheInsResult.SuccessNearEvicition: case CacheInsResult.Success: if (isUserOperation) { _logMgr.LogOperation(bucketId, key, clone, OperationType.Insert); } IncrementBucketStats(key as string, bucketId, cacheEntry.DataSize); break; case CacheInsResult.SuccessOverwriteNearEviction: case CacheInsResult.SuccessOverwrite: if (isUserOperation) { _logMgr.LogOperation(bucketId, key, clone, OperationType.Insert); } DecrementBucketStats(key as string, bucketId, oldEntrysize); IncrementBucketStats(key as string, bucketId, cacheEntry.DataSize); break; } return(result); } throw new StateTransferException("I am no more the owner of this bucket"); }
internal override CacheInsResult InsertInternal(object key, CacheEntry cacheEntry, bool isUserOperation, CacheEntry oldEntry, OperationContext operationContext, bool updateIndex) { int bucketId = GetBucketId(key as string); if (IsBucketTransfered(bucketId)) { throw new StateTransferException("I am no more the owner of this bucket"); } long oldEntrysize = oldEntry == null ? 0 : oldEntry.DataSize; if (_logMgr.IsLoggingEnbaled(bucketId, LogMode.LogBeforeActualOperation) && isUserOperation) { _logMgr.LogOperation(bucketId, key, cacheEntry, OperationType.Insert); return(oldEntry != null ? CacheInsResult.SuccessOverwrite : CacheInsResult.Success); } CacheInsResult result = base.InsertInternal(key, cacheEntry, isUserOperation, oldEntry, operationContext, updateIndex); switch (result) { case CacheInsResult.SuccessNearEvicition: case CacheInsResult.Success: if (isUserOperation) { _logMgr.LogOperation(bucketId, key, cacheEntry, OperationType.Insert); } IncrementBucketStats(key as string, bucketId, cacheEntry.DataSize); break; case CacheInsResult.SuccessOverwriteNearEviction: case CacheInsResult.SuccessOverwrite: if (isUserOperation) { _logMgr.LogOperation(bucketId, key, cacheEntry, OperationType.Insert); } DecrementBucketStats(key as string, bucketId, oldEntrysize); IncrementBucketStats(key as string, bucketId, cacheEntry.DataSize); break; } return(result); }
/// <summary> /// Método interno usado para inserir uma nova entrada no cache. /// </summary> /// <param name="key">Chave que representa a entrada.</param> /// <param name="cacheEntry">Instancia da entrada.</param> /// <param name="isUserOperation">True se for uma operação do usuário.</param> /// <param name="oldEntry">Valor da antiga entrada.</param> /// <param name="operationContext">Contexto da operação.</param> /// <returns>Resulta da operação.</returns> internal override CacheInsResult InsertInternal(object key, CacheEntry cacheEntry, bool isUserOperation, CacheEntry oldEntry, OperationContext operationContext) { if (oldEntry != null && !CacheHelper.CheckDataGroupsCompatibility(cacheEntry.GroupInfo, oldEntry.GroupInfo)) { return(CacheInsResult.IncompatibleGroup); } CacheInsResult result = base.InsertInternal(key, cacheEntry, isUserOperation, oldEntry, operationContext); switch (result) { case CacheInsResult.Success: case CacheInsResult.SuccessNearEvicition: _grpIndexManager.AddToGroup(key, cacheEntry.GroupInfo); if ((_queryIndexManager != null) && (cacheEntry.QueryInfo != null)) { _queryIndexManager.AddToIndex(key, cacheEntry); } return(result); case CacheInsResult.SuccessOverwrite: case CacheInsResult.SuccessOverwriteNearEviction: if (oldEntry != null) { _grpIndexManager.RemoveFromGroup(key, oldEntry.GroupInfo); } _grpIndexManager.AddToGroup(key, cacheEntry.GroupInfo); if (_queryIndexManager == null) { return(result); } if (oldEntry != null && oldEntry.QueryInfo != null) { _queryIndexManager.RemoveFromIndex(key, oldEntry.QueryInfo); } if (cacheEntry.QueryInfo != null) { _queryIndexManager.AddToIndex(key, cacheEntry); } break; } return(result); }
/// <summary> /// Updates or Adds the object to the cluster. /// </summary> /// <param name="key">key of the entry.</param> /// <returns>cache entry.</returns> /// <remarks> /// This method invokes <see cref="handleInsert"/> on the specified node. /// </remarks> protected CacheInsResult Clustered_Insert(Address dest, object key, CacheEntry cacheEntry, OperationContext operationContext) { CacheInsResult retVal = CacheInsResult.Failure; try { Function func = new Function((int)OpCodes.Insert, new object[] { key, cacheEntry, operationContext }, false, key); Array userPayLoad = null; if (cacheEntry.Value is CallbackEntry) { CallbackEntry cbEntry = ((CallbackEntry)cacheEntry.Value); userPayLoad = cbEntry.UserData; } else { userPayLoad = cacheEntry.UserData; } func.UserPayload = userPayLoad; object result = Cluster.SendMessage(dest, func, GroupRequest.GET_FIRST, _asyncOperation); if (result == null) { return(retVal); } retVal = (CacheInsResult)result; } catch (CacheException e) { throw; } catch (Exception e) { throw new GeneralFailureException(e.Message, e); } return(retVal); }
void ICompactSerializable.Deserialize(CompactReader reader) { _entry = (CacheEntry)reader.ReadObject(); _result = (CacheInsResult)reader.ReadObject(); }
/// <summary> /// constructor /// </summary> /// <param name="entry"></param> /// <param name="result"></param> public CacheInsResultWithEntry(CacheEntry entry, CacheInsResult result) { _entry = entry; _result = result; }
public override void ResetLeasable() { _result = CacheInsResult.Success; _entry = null; }