@Override public void onAction(VBucketStore cacheStore, Item itm) { if (storage.persistEnabled) { storage.persistDeletedItem(itm.getKeySpec()); } if (storage.replicationEnabled) { storage.replicateDeletedItem(itm.getKeySpec()); } }
public void replicateMutatedItem(Item itm) { VBucketInfo vbi = vbInfo[itm.getKeySpec().vbId]; if (vbi.getOwner() != server) { return; } for (MemcachedServer replica : vbi.getReplicas()) { Item newItem = new Item(itm); VBucketStore rStore = replica.getStorage().cacheStore; rStore.getMap().put(newItem.getKeySpec(), newItem); rStore.onItemMutated.onAction(rStore, newItem); } }
public void persistMutatedItem(Item itm) { persistStore.put(itm.getKeySpec(), new Item(itm)); }
public void putPersisted(Item itm) { persistStore.put(itm.getKeySpec(), itm); }
public void putCached(Item itm) { cacheStore.getMap().put(itm.getKeySpec(), itm); }
private void executeReal(JsonObject payload, Command command) { final String value; long cas = 0; boolean onMaster; JsonElement eOnReplicas; Storage masterStore; List<Storage> stores = new ArrayList<Storage>(); onMaster = payload.get("OnMaster").getAsBoolean(); if (payload.has("CAS")) { cas = payload.get("CAS").getAsLong(); } if (payload.has("Value")) { value = payload.get("Value").getAsString(); } else { value = ""; } masterStore = vbi.getOwner().getStorage(); if (onMaster) { stores.add(masterStore); } // Figure out which replicas to affect eOnReplicas = payload.get("OnReplicas"); if (eOnReplicas.isJsonArray()) { // An array of indices to use: for (JsonElement ix : eOnReplicas.getAsJsonArray()) { MemcachedServer mc = vbi.getReplicas().get(ix.getAsInt()); Storage s = mc.getStorage(); if (!stores.contains(s)) { stores.add(s); } } } else { int maxReplicas = eOnReplicas.getAsInt(); int replicasSelected = 0; for (MemcachedServer server : vbi.getReplicas()) { if (replicasSelected == maxReplicas) { break; } if (!server.isActive()) { continue; } stores.add(server.getStorage()); replicasSelected++; } } Item source = masterStore.getCached(keySpec); Item newItem; if (source == null) { assert value != null; assert value.getBytes() != null; source = new Item(keySpec, 0, 0, value.getBytes(), cas); } if (cas < 0) { cas = (source.getCas() + 1) * 2; } if (cas != 0) { newItem = new Item( source.getKeySpec(), source.getFlags(), source.getExpiryTime(), value.getBytes(), cas); } else { newItem = new Item(source); } if (stores.size() == 0) { System.err.println("No stores available for key"); } for (Storage curStore : stores) { switch (command) { case PERSIST: case ENDURE: curStore.putPersisted(newItem); if (command == Command.PERSIST) { break; } // ENDURE fallthrough case CACHE: curStore.putCached(newItem); break; case PURGE: case UNPERSIST: curStore.removePersisted(keySpec); if (command == Command.UNPERSIST) { break; } case UNCACHE: curStore.removeCached(keySpec); break; default: throw new RuntimeException("Unrecognized command"); } } }