Package org.apache.bookkeeper.client.QuorumEngine.SubOp

Examples of org.apache.bookkeeper.client.QuorumEngine.SubOp.SubAddOp


                        client.errorOut();                  
                        cleanQueue();
                        LOG.debug("Stopped");
                        break;
                    case Operation.ADD:
                        SubAddOp aOp = (SubAddOp) ts.ctx;
                        AddOp op = ((AddOp) aOp.op);
                       
                        long confirmed = self.getAddConfirmed();
                        ByteBuffer extendedData;
   
View Full Code Here


        stop = true;
        ToSend ts = incomingQueue.poll();
        while(ts != null){
            switch(ts.type){
            case Operation.ADD:
                SubAddOp aOp = (SubAddOp) ts.ctx;
                aOp.wcb.writeComplete(-1, ts.lh.getId(), ts.entry, ts.ctx);
    
                break;
            case Operation.READ:               
                ((SubReadOp) ts.ctx).rcb.readEntryComplete(-1, ts.lh.getId(), ts.entry, null, ts.ctx);
View Full Code Here

            try{
                ToSend ts = incomingQueue.poll(1000, TimeUnit.MILLISECONDS);
                if(ts != null){
                    switch(ts.type){
                    case Operation.ADD:
                        SubAddOp aOp = (SubAddOp) ts.ctx;
                        AddOp op = ((AddOp) aOp.op);
                       
                        /*
                         * TODO: Really add the confirmed add to the op
                         */
 
View Full Code Here

        String logmsg;
       
        //synchronized(pendingAdds){
        //pOp = pendingAdds.get(entryId);
        //}
        SubAddOp sAdd = (SubAddOp) ctx;
        PendingOp pOp = sAdd.pOp;
        Integer sId = sAdd.bIndex;
       
        if(pOp == null){
            LOG.error("No such an entry ID: " + entryId + "(" + ledgerId + ")");
            return;
        }
       
        ArrayList<BookieHandle> list = lh.getBookies();
        int n = list.size();
        
        if(rc == 0){
            // Everything went ok with this op
            synchronized(pOp){
                //pOp.bookieIdSent.add(sId);
                pOp.bookieIdRecv.add(sId);
                if(pOp.bookieIdRecv.size() == lh.getQuorumSize()){
                    //pendingAdds.remove(entryId);
                    //sAdd.op.cb.addComplete(sAdd.op.getErrorCode(),
                    //        ledgerId, entryId, sAdd.op.ctx);
                    sAdd.op.setReady();    
                }
            }
        } else {
            LOG.error("Error sending write request: " + rc + " : " + ledgerId);
            HashSet<Integer> ids;
             
            synchronized(pOp){
                pOp.bookieIdSent.add(sId);
                ids = pOp.bookieIdSent;               
                //Check if we tried all possible bookies already
                if(ids.size() == lh.getBookies().size()){
                    if(pOp.retries++ >= MAXRETRIES){
                        //Call back with error code
                        //sAdd.op.cb.addComplete(ErrorCodes.ENUMRETRIES,
                        //        ledgerId, entryId, sAdd.op.ctx);
                        sAdd.op.setErrorCode(ErrorCodes.ENUMRETRIES);
                        sAdd.op.setReady();
                        return;
                    }
                   
                    ids.clear();
                }
                // Select another bookie that we haven't contacted yet
                for(int i = 0; i < lh.getBookies().size(); i++){
                    if(!ids.contains(Integer.valueOf(i))){
                        // and send it to new bookie
                        try{
                            list.get(i).sendAdd(new SubAddOp(sAdd.op,
                                    pOp,
                                    i,
                                    this), ((AddOp) sAdd.op).entry);
                            pOp.bookieIdRecv.add(sId.intValue());
                               
View Full Code Here

    public void writeComplete(int rc, long ledgerId, long entryId, Object ctx){
        //PendingAddOp pOp;
        //synchronized(pendingAdds){
        //pOp = pendingAdds.get(entryId);
        //}
        SubAddOp sAdd = (SubAddOp) ctx;
        PendingOp pOp = sAdd.pOp;
        Integer sId = sAdd.bIndex;
       
        if(pOp == null){
            LOG.error("No such an entry ID: " + entryId + "(" + ledgerId + ")");
            return;
        }
       
        ArrayList<BookieHandle> list = lh.getBookies();
        if(rc == 0){
            // Everything went ok with this op
            synchronized(pOp){
                pOp.bookieIdRecv.add(sId);
                lh.setLastRecvCorrectly(sId, entryId);
                if(pOp.bookieIdRecv.size() >= lh.getQuorumSize()){
                    sAdd.op.setReady();    
                }
            }
        } else {
            //LOG.warn("Error sending write request: " + rc + " : " + ledgerId + ": " + lh.getBookies().size());
            /*
             * If ledger is closed already, then simply return
             */
            if(lh.getId() == -1){
                LOG.warn("Ledger identifier is not valid");
                return;
            }
           
            HashSet<Integer> ids;
             
            synchronized(pOp){
                pOp.bookieIdSent.add(sId);
                ids = pOp.bookieIdSent;               
                //Check if we tried all possible bookies already
                if(ids.size() == lh.getBookies().size()){
                    if(pOp.retries++ >= MAXRETRIES){
                        //Call back with error code
 
                        sAdd.op.setErrorCode(BKDefs.ENR);
                        sAdd.op.setReady();
                        return;
                    }
                   
                    ids.clear();
                }
                // Select another bookie that we haven't contacted yet
                try{
                    //LOG.info("Selecting another bookie " + entryId);
                    int bCounter;
                    if(sId >= (entryId % (lh.getBookies().size() + 1))){
                        bCounter = sId - (((int) entryId) % (lh.getBookies().size() + 1));
                    } else {
                        bCounter = (lh.getBookies().size() + 1) - (((int) entryId) % (lh.getBookies().size() + 1)) - sId;
                    }
                   
                    int tmpId = (((int) entryId) + lh.getQuorumSize()) % (lh.getBookies().size() + 1);
                    int newId = tmpId % lh.getBookies().size();
                    //LOG.info("Sending a new add operation to bookie: " + newId + ", " + lh.getBookies().get(newId).addr);
                   
                    BookieHandle bh = lh.getBookies().get(newId);
                   
                    //LOG.info("Got handle for " + newId);
                   
                    bh.sendAdd(lh, new SubAddOp(sAdd.op,
                            pOp,
                            newId,
                            this), entryId);
              
                    //LOG.info("Ended " + entryId + ", " + newId);
View Full Code Here

                        client.errorOut();                  
                        cleanQueue();
                        LOG.debug("Stopped");
                        break;
                    case Operation.ADD:
                        SubAddOp aOp = (SubAddOp) ts.ctx;
                        AddOp op = ((AddOp) aOp.op);
                       
                        long confirmed = self.getAddConfirmed();
                        ByteBuffer extendedData;
   
View Full Code Here

        stop = true;
        ToSend ts = incomingQueue.poll();
        while(ts != null){
            switch(ts.type){
            case Operation.ADD:
                SubAddOp aOp = (SubAddOp) ts.ctx;
                aOp.wcb.writeComplete(-1, ts.lh.getId(), ts.entry, ts.ctx);
    
                break;
            case Operation.READ:               
                ((SubReadOp) ts.ctx).rcb.readEntryComplete(-1, ts.lh.getId(), ts.entry, null, ts.ctx);
View Full Code Here

TOP

Related Classes of org.apache.bookkeeper.client.QuorumEngine.SubOp.SubAddOp

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.