/** * Drops messages to/from other members and then closes the channel. Note that this member won't get excluded from * the view until failure detection has kicked in and the new coord installed the new view */ public static void shutdown(JChannel ch) throws Exception { DISCARD discard=new DISCARD(); discard.setLocalAddress(ch.getAddress()); discard.setDiscardAll(true); ProtocolStack stack=ch.getProtocolStack(); TP transport=stack.getTransport(); stack.insertProtocol(discard,ProtocolStack.Position.ABOVE,transport.getClass()); //abruptly shutdown FD_SOCK just as in real life when member gets killed non gracefully FD_SOCK fd=ch.getProtocolStack().findProtocol(FD_SOCK.class); if(fd != null) fd.stopServerSocket(false); View view=ch.getView(); if(view != null) { ViewId vid=view.getViewId(); List<Address> members=Collections.singletonList(ch.getAddress()); ViewId new_vid=new ViewId(ch.getAddress(),vid.getId() + 1); View new_view=new View(new_vid,members); // inject view in which the shut down member is the only element GMS gms=stack.findProtocol(GMS.class); gms.installView(new_view); } Util.close(ch); }
void init() { getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); checkboxes.setLayout(new BoxLayout(checkboxes, BoxLayout.Y_AXIS)); getContentPane().add(start_discarding_button); getContentPane().add(stop_discarding_button); start_discarding_button.addActionListener(this); stop_discarding_button.addActionListener(this); getContentPane().add(checkboxes); pack(); setVisible(true); setTitle(localAddress() != null? localAddress().toString() : "n/a"); }
public Object up(Message msg) { if(shouldDropUpMessage(msg, msg.getSrc())) return null; return up_prot.up(msg); }
@Override public <T> CompletionStage<T> invokeCommand(Address target, ReplicableCommand command, ResponseCollector<T> collector, DeliverOrder deliverOrder, long timeout, TimeUnit unit) { if (command instanceof StateRequestCommand && ((StateRequestCommand) command).getType() == StateRequestCommand.Type.START_STATE_TRANSFER && target.equals(address(1))) { d1.setDiscardAll(true); fork((Callable<Void>) () -> { log.info("KILLING the c1 cache"); TestingUtil.killCacheManagers(manager(c1)); return null; }); } return super.invokeCommand(target, command, collector, deliverOrder, timeout, unit); } });
/** * Simulates a node crash, discarding all the messages from/to this node and then stopping the caches. */ public static void crashCacheManagers(EmbeddedCacheManager... cacheManagers) { for (EmbeddedCacheManager cm : cacheManagers) { JGroupsTransport t = (JGroupsTransport) cm.getGlobalComponentRegistry().getComponent(Transport.class); JChannel channel = t.getChannel(); try { DISCARD discard = new DISCARD(); discard.setDiscardAll(true); channel.getProtocolStack().insertProtocol(discard, ProtocolStack.Position.ABOVE, TP.class); } catch (Exception e) { log.warn("Problems inserting discard", e); throw new RuntimeException(e); } View view = View.create(channel.getAddress(), 100, channel.getAddress()); ((GMS) channel.getProtocolStack().findProtocol(GMS.class)).installView(view); } killCacheManagers(cacheManagers); }
private void discardOtherMembers() { List<Address> outsideMembers = new ArrayList<>(); for (Address a : allMembers) { boolean inThisPartition = false; for (JChannel c : channels) { if (c.getAddress().equals(a)) inThisPartition = true; } if (!inThisPartition) outsideMembers.add(a); } for (JChannel c : channels) { DISCARD discard = new DISCARD(); for (Address a : outsideMembers) discard.addIgnoreMember(a); try { c.getProtocolStack().insertProtocol(discard, ProtocolStack.Position.ABOVE, TP.class); } catch (Exception e) { throw new RuntimeException(e); } } }
public static DISCARD getDiscardForCache(EmbeddedCacheManager cacheManager) throws Exception { JGroupsTransport jgt = (JGroupsTransport) TestingUtil.extractGlobalComponent(cacheManager, Transport.class); JChannel ch = jgt.getChannel(); ProtocolStack ps = ch.getProtocolStack(); DISCARD discard = new DISCARD(); discard.setExcludeItself(false); ps.insertProtocol(discard, ProtocolStack.Position.ABOVE, TP.class); return discard; }
public DISCARD localAddress(Address addr) {setLocalAddress(addr); return this;}
if (partitionOne.contains(address(i))) { for (Address a : partitionTwo) { discards[i].addIgnoreMember(((JGroupsAddress) a).getJGroupsAddress()); discards[i].addIgnoreMember(((JGroupsAddress) a).getJGroupsAddress()); discards[i].resetIgnoredMembers();
msg=(Message)evt.getArg(); Address sender=msg.getSrc(); DiscardHeader dh = (DiscardHeader) msg.getHeader(getName()); if (dh != null) { ignoredMembers.clear();
private boolean isDiscardEnabled(TEST_PING discovery) { // Not pretty but since this protocol does not rely on the transport, the // only possible way to discard messages is by hacking the protocol itself. List<Protocol> protocols = discovery.getProtocolStack().getProtocols(); for (Protocol protocol : protocols) { if (protocol instanceof DISCARD) { discovery.discard = (DISCARD) protocol; } } return discovery.discard != null && discovery.discard.isDiscardAll(); }
private void observeMembers(Partition partition) { for (JChannel c : channels) { List<Protocol> protocols = c.getProtocolStack().getProtocols(); for (Protocol p : protocols) { if (p instanceof DISCARD) { for (JChannel oc : partition.channels) { ((DISCARD) p).removeIgnoredMember(oc.getAddress()); } } } } }
public void testClusterRecoveryAfterThreeWaySplit() throws Exception { d1.setDiscardAll(true); d2.setDiscardAll(true); d3.setDiscardAll(true); d1.setDiscardAll(false); d2.setDiscardAll(false); d3.setDiscardAll(false);
public DISCARD localAddress(Address addr) {setLocalAddress(addr); return this;}
d1.setDiscardAll(true); d2.setDiscardAll(true); d1.setDiscardAll(false); d2.setDiscardAll(false);
/** * Drops messages to/from other members and then closes the channel. Note that this member won't get excluded from * the view until failure detection has kicked in and the new coord installed the new view */ public static void shutdown(JChannel ch) throws Exception { DISCARD discard=new DISCARD(); discard.setLocalAddress(ch.getAddress()); discard.setDiscardAll(true); ProtocolStack stack=ch.getProtocolStack(); TP transport=stack.getTransport(); stack.insertProtocol(discard,ProtocolStack.Position.ABOVE,transport.getClass()); //abruptly shutdown FD_SOCK just as in real life when member gets killed non gracefully FD_SOCK fd=ch.getProtocolStack().findProtocol(FD_SOCK.class); if(fd != null) fd.stopServerSocket(false); View view=ch.getView(); if(view != null) { ViewId vid=view.getViewId(); List<Address> members=Collections.singletonList(ch.getAddress()); ViewId new_vid=new ViewId(ch.getAddress(),vid.getId() + 1); View new_view=new View(new_vid,members); // inject view in which the shut down member is the only element GMS gms=stack.findProtocol(GMS.class); gms.installView(new_view); } Util.close(ch); }
@ManagedOperation public void startGui() { if(discard_dialog == null) { discard_dialog=new DiscardDialog(); discard_dialog.init(); discard_dialog.setTitle(localAddress() != null? localAddress().toString() : "n/a"); discard_dialog.handleView(members); } }
public void up(MessageBatch batch) { for(Iterator<Message> it=batch.iterator(); it.hasNext();) { Message msg=it.next(); if(msg != null && shouldDropUpMessage(msg, msg.getSrc())) it.remove(); } if(!batch.isEmpty()) up_prot.up(batch); }
public void testClusterRecoveryAfterSplitAndCoordLeave() throws Exception { d1.setDiscardAll(true); d2.setDiscardAll(true); d3.setDiscardAll(true); d2.setDiscardAll(false); d3.setDiscardAll(false);
/** Checks if a message should be passed up, or not */ protected boolean shouldDropUpMessage(@SuppressWarnings("UnusedParameters") Message msg, Address sender) { if(discard_all && !sender.equals(localAddress())) return true; if(ignoredMembers.contains(sender)) { if(log.isTraceEnabled()) log.trace(localAddress + ": dropping message from " + sender); num_up++; return true; } if(up > 0) { double r=Math.random(); if(r < up) { if(excludeItself && sender.equals(localAddress())) { if(log.isTraceEnabled()) log.trace("excluding myself"); } else { if(log.isTraceEnabled()) log.trace(localAddress + ": dropping message from " + sender); num_up++; return true; } } } return false; }