@Override public void onAction(VBucketStore cacheStore, Item itm) { if (storage.persistEnabled) { storage.persistDeletedItem(itm.getKeySpec()); } if (storage.replicationEnabled) { storage.replicateDeletedItem(itm.getKeySpec()); } }
@Override public void onAction(VBucketStore cacheStore, Item itm) { if (storage.persistEnabled) { storage.persistMutatedItem(itm); } if (storage.replicationEnabled) { storage.replicateMutatedItem(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"); } } }