当前位置: 首页>>代码示例>>Java>>正文


Java ChangeRecord类代码示例

本文整理汇总了Java中org.apache.zookeeper.server.ZooKeeperServer.ChangeRecord的典型用法代码示例。如果您正苦于以下问题:Java ChangeRecord类的具体用法?Java ChangeRecord怎么用?Java ChangeRecord使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ChangeRecord类属于org.apache.zookeeper.server.ZooKeeperServer包,在下文中一共展示了ChangeRecord类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPendingChanges

import org.apache.zookeeper.server.ZooKeeperServer.ChangeRecord; //导入依赖的package包/类
/**
 * Grab current pending change records for each op in a multi-op.
 * 
 * This is used inside MultiOp error code path to rollback in the event
 * of a failed multi-op.
 *
 * @param multiRequest
 */
HashMap<String, ChangeRecord> getPendingChanges(MultiTransactionRecord multiRequest) {
	HashMap<String, ChangeRecord> pendingChangeRecords = new HashMap<String, ChangeRecord>();
	
    for(Op op: multiRequest) {
		String path = op.getPath();

		try {
			ChangeRecord cr = getRecordForPath(path);
			if (cr != null) {
				pendingChangeRecords.put(path, cr);
			}
		} catch (KeeperException.NoNodeException e) {
			// ignore this one
		}
	}
    
    return pendingChangeRecords;
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:27,代码来源:PrepRequestProcessor.java

示例2: getPendingChanges

import org.apache.zookeeper.server.ZooKeeperServer.ChangeRecord; //导入依赖的package包/类
/**
 * Grab current pending change records for each op in a multi-op.
 * 
 * This is used inside MultiOp error code path to rollback in the event
 * of a failed multi-op.
 *
 * @param multiRequest
 * @return a map that contains previously existed records that probably need to be
 *         rolled back in any failure.
 */
HashMap<String, ChangeRecord> getPendingChanges(MultiTransactionRecord multiRequest) {
    HashMap<String, ChangeRecord> pendingChangeRecords = new HashMap<String, ChangeRecord>();

    for (Op op : multiRequest) {
        String path = op.getPath();
        ChangeRecord cr = getOutstandingChange(path);
        // only previously existing records need to be rolled back.
        if (cr != null) {
            pendingChangeRecords.put(path, cr);
        }

        /*
         * ZOOKEEPER-1624 - We need to store for parent's ChangeRecord
         * of the parent node of a request. So that if this is a
         * sequential node creation request, rollbackPendingChanges()
         * can restore previous parent's ChangeRecord correctly.
         *
         * Otherwise, sequential node name generation will be incorrect
         * for a subsequent request.
         */
        int lastSlash = path.lastIndexOf('/');
        if (lastSlash == -1 || path.indexOf('\0') != -1) {
            continue;
        }
        String parentPath = path.substring(0, lastSlash);
        ChangeRecord parentCr = getOutstandingChange(parentPath);
        if (parentCr != null) {
            pendingChangeRecords.put(parentPath, parentCr);
        }
    }

    return pendingChangeRecords;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:44,代码来源:PrepRequestProcessor.java

示例3: testMultiOutstandingChange

import org.apache.zookeeper.server.ZooKeeperServer.ChangeRecord; //导入依赖的package包/类
/**
 * This test checks that a successful multi will change outstanding record
 * and failed multi shouldn't change outstanding record.
 */
@Test
public void testMultiOutstandingChange() throws Exception {
    zks.getZKDatabase().dataTree.createNode("/foo", new byte[0], Ids.OPEN_ACL_UNSAFE, 0, 0, 0, 0);

    Assert.assertNull(zks.outstandingChangesForPath.get("/foo"));

    process(Arrays.asList(
            Op.setData("/foo", new byte[0], -1)));

    ChangeRecord cr = zks.outstandingChangesForPath.get("/foo");
    Assert.assertNotNull("Change record wasn't set", cr);
    Assert.assertEquals("Record zxid wasn't set correctly",
            1, cr.zxid);

    process(Arrays.asList(
            Op.delete("/foo", -1)));
    cr = zks.outstandingChangesForPath.get("/foo");
    Assert.assertEquals("Record zxid wasn't set correctly",
            2, cr.zxid);


    // It should fail and shouldn't change outstanding record.
    process(Arrays.asList(
            Op.delete("/foo", -1)));
    cr = zks.outstandingChangesForPath.get("/foo");
    // zxid should still be previous result because record's not changed.
    Assert.assertEquals("Record zxid wasn't set correctly",
            2, cr.zxid);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:34,代码来源:PrepRequestProcessorTest.java

示例4: getPendingChanges

import org.apache.zookeeper.server.ZooKeeperServer.ChangeRecord; //导入依赖的package包/类
/**
 * Grab current pending change records for each op in a multi-op.
 *
 * This is used inside MultiOp error code path to rollback in the event
 * of a failed multi-op.
 *
 * @param multiRequest
 * @return a map that contains previously existed records that probably need to be
 *         rolled back in any failure.
 */
private Map<String, ChangeRecord> getPendingChanges(MultiTransactionRecord multiRequest) {
    Map<String, ChangeRecord> pendingChangeRecords = new HashMap<String, ChangeRecord>();

    for (Op op : multiRequest) {
        String path = op.getPath();
        ChangeRecord cr = getOutstandingChange(path);
        // only previously existing records need to be rolled back.
        if (cr != null) {
            pendingChangeRecords.put(path, cr);
        }

        /*
         * ZOOKEEPER-1624 - We need to store for parent's ChangeRecord
         * of the parent node of a request. So that if this is a
         * sequential node creation request, rollbackPendingChanges()
         * can restore previous parent's ChangeRecord correctly.
         *
         * Otherwise, sequential node name generation will be incorrect
         * for a subsequent request.
         */
        int lastSlash = path.lastIndexOf('/');
        if (lastSlash == -1 || path.indexOf('\0') != -1) {
            continue;
        }
        String parentPath = path.substring(0, lastSlash);
        ChangeRecord parentCr = getOutstandingChange(parentPath);
        if (parentCr != null) {
            pendingChangeRecords.put(parentPath, parentCr);
        }
    }

    return pendingChangeRecords;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:44,代码来源:PrepRequestProcessor.java

示例5: getPendingChanges

import org.apache.zookeeper.server.ZooKeeperServer.ChangeRecord; //导入依赖的package包/类
/**
 * Grab current pending change records for each op in a multi-op.
 *
 * This is used inside MultiOp error code path to rollback in the event
 * of a failed multi-op.
 *
 * @param multiRequest
 * @return a map that contains previously existed records that probably need to be
 *         rolled back in any failure.
 */
private Map<String, ChangeRecord> getPendingChanges(MultiTransactionRecord multiRequest) {
    HashMap<String, ChangeRecord> pendingChangeRecords = new HashMap<String, ChangeRecord>();

    for (Op op : multiRequest) {
        String path = op.getPath();
        ChangeRecord cr = getOutstandingChange(path);
        // only previously existing records need to be rolled back.
        if (cr != null) {
            pendingChangeRecords.put(path, cr);
        }

        /*
         * ZOOKEEPER-1624 - We need to store for parent's ChangeRecord
         * of the parent node of a request. So that if this is a
         * sequential node creation request, rollbackPendingChanges()
         * can restore previous parent's ChangeRecord correctly.
         *
         * Otherwise, sequential node name generation will be incorrect
         * for a subsequent request.
         */
        int lastSlash = path.lastIndexOf('/');
        if (lastSlash == -1 || path.indexOf('\0') != -1) {
            continue;
        }
        String parentPath = path.substring(0, lastSlash);
        ChangeRecord parentCr = getOutstandingChange(parentPath);
        if (parentCr != null) {
            pendingChangeRecords.put(parentPath, parentCr);
        }
    }

    return pendingChangeRecords;
}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:44,代码来源:PrepRequestProcessor.java

示例6: getPendingChanges

import org.apache.zookeeper.server.ZooKeeperServer.ChangeRecord; //导入依赖的package包/类
/**
 * Grab current pending change records for each op in a multi-op.
 * 
 * This is used inside MultiOp error code path to rollback in the event
 * of a failed multi-op.
 *
 * @param multiRequest
 */
HashMap<String, ChangeRecord> getPendingChanges(MultiTransactionRecord multiRequest) {
	HashMap<String, ChangeRecord> pendingChangeRecords = new HashMap<String, ChangeRecord>();
	
    for(Op op: multiRequest) {
		String path = op.getPath();

		try {
		    ChangeRecord cr = getRecordForPath(path);
		    if (cr != null) {
		        pendingChangeRecords.put(path, cr);
		    }
		    /*
		     * ZOOKEEPER-1624 - We need to store for parent's ChangeRecord
		     * of the parent node of a request. So that if this is a
		     * sequential node creation request, rollbackPendingChanges()
		     * can restore previous parent's ChangeRecord correctly.
		     *
		     * Otherwise, sequential node name generation will be incorrect
		     * for a subsequent request.
		     */
		    int lastSlash = path.lastIndexOf('/');
		    if (lastSlash == -1 || path.indexOf('\0') != -1) {
		        continue;
		    }
		    String parentPath = path.substring(0, lastSlash);
		    ChangeRecord parentCr = getRecordForPath(parentPath);
		    if (parentCr != null) {
		        pendingChangeRecords.put(parentPath, parentCr);
		    }
		} catch (KeeperException.NoNodeException e) {
			// ignore this one
		}
	}
    
    return pendingChangeRecords;
}
 
开发者ID:wangyangjun,项目名称:StreamBench,代码行数:45,代码来源:PrepRequestProcessor.java

示例7: getOutstandingChange

import org.apache.zookeeper.server.ZooKeeperServer.ChangeRecord; //导入依赖的package包/类
private ChangeRecord getOutstandingChange(String path) {
    synchronized (zks.outstandingChanges) {
        return zks.outstandingChangesForPath.get(path);
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:6,代码来源:PrepRequestProcessor.java

示例8: addChangeRecord

import org.apache.zookeeper.server.ZooKeeperServer.ChangeRecord; //导入依赖的package包/类
void addChangeRecord(ChangeRecord c) {
    synchronized (zks.outstandingChanges) {
        zks.outstandingChanges.add(c);
        zks.outstandingChangesForPath.put(c.path, c);
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:7,代码来源:PrepRequestProcessor.java

示例9: addChangeRecord

import org.apache.zookeeper.server.ZooKeeperServer.ChangeRecord; //导入依赖的package包/类
private void addChangeRecord(ChangeRecord c) {
    synchronized (zks.outstandingChanges) {
        zks.outstandingChanges.add(c);
        zks.outstandingChangesForPath.put(c.path, c);
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:7,代码来源:PrepRequestProcessor.java

示例10: pRequest2TxnCreate

import org.apache.zookeeper.server.ZooKeeperServer.ChangeRecord; //导入依赖的package包/类
private void pRequest2TxnCreate(int type, Request request, Record record, boolean deserialize) throws IOException, KeeperException {
    if (deserialize) {
        ByteBufferInputStream.byteBuffer2Record(request.request, record);
    }

    int flags;
    String path;
    List<ACL> acl;
    byte[] data;
    long ttl;
    if (type == OpCode.createTTL) {
        CreateTTLRequest createTtlRequest = (CreateTTLRequest)record;
        flags = createTtlRequest.getFlags();
        path = createTtlRequest.getPath();
        acl = createTtlRequest.getAcl();
        data = createTtlRequest.getData();
        ttl = createTtlRequest.getTtl();
    } else {
        CreateRequest createRequest = (CreateRequest)record;
        flags = createRequest.getFlags();
        path = createRequest.getPath();
        acl = createRequest.getAcl();
        data = createRequest.getData();
        ttl = -1;
    }
    CreateMode createMode = CreateMode.fromFlag(flags);
    validateCreateRequest(path, createMode, request, ttl);
    String parentPath = validatePathForCreate(path, request.sessionId);

    List<ACL> listACL = fixupACL(path, request.authInfo, acl);
    ChangeRecord parentRecord = getRecordForPath(parentPath);

    checkACL(zks, request.cnxn, parentRecord.acl, ZooDefs.Perms.CREATE, request.authInfo, path, listACL);
    int parentCVersion = parentRecord.stat.getCversion();
    if (createMode.isSequential()) {
        path = path + String.format(Locale.ENGLISH, "%010d", parentCVersion);
    }
    validatePath(path, request.sessionId);
    try {
        if (getRecordForPath(path) != null) {
            throw new KeeperException.NodeExistsException(path);
        }
    } catch (KeeperException.NoNodeException e) {
        // ignore this one
    }
    boolean ephemeralParent = EphemeralType.get(parentRecord.stat.getEphemeralOwner()) == EphemeralType.NORMAL;
    if (ephemeralParent) {
        throw new KeeperException.NoChildrenForEphemeralsException(path);
    }
    int newCversion = parentRecord.stat.getCversion()+1;
    if (type == OpCode.createContainer) {
        request.setTxn(new CreateContainerTxn(path, data, listACL, newCversion));
    } else if (type == OpCode.createTTL) {
        request.setTxn(new CreateTTLTxn(path, data, listACL, newCversion, ttl));
    } else {
        request.setTxn(new CreateTxn(path, data, listACL, createMode.isEphemeral(),
                newCversion));
    }
    StatPersisted s = new StatPersisted();
    if (createMode.isEphemeral()) {
        s.setEphemeralOwner(request.sessionId);
    }
    parentRecord = parentRecord.duplicate(request.getHdr().getZxid());
    parentRecord.childCount++;
    parentRecord.stat.setCversion(newCversion);
    addChangeRecord(parentRecord);
    addChangeRecord(new ChangeRecord(request.getHdr().getZxid(), path, s, 0, listACL));
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:69,代码来源:PrepRequestProcessor.java


注:本文中的org.apache.zookeeper.server.ZooKeeperServer.ChangeRecord类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。