Browse Source

Added MerkleDataCluster;

tags/1.1.2^2
huanghaiquan 5 years ago
parent
commit
6167bb7d89
2 changed files with 79 additions and 5 deletions
  1. +76
    -0
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleDataCluster.java
  2. +3
    -5
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleDataSet.java

+ 76
- 0
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleDataCluster.java View File

@@ -0,0 +1,76 @@
package com.jd.blockchain.ledger.core;

import java.util.Map;

import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.ledger.CryptoSetting;
import com.jd.blockchain.ledger.MerkleProof;
import com.jd.blockchain.ledger.MerkleSnapshot;
import com.jd.blockchain.storage.service.ExPolicyKVStorage;
import com.jd.blockchain.storage.service.VersioningKVStorage;
import com.jd.blockchain.utils.Bytes;
import com.jd.blockchain.utils.Transactional;
import com.jd.blockchain.utils.VersioningMap;

public class MerkleDataCluster implements Transactional, MerkleSnapshot {

private boolean readonly;

private MerkleDataSet rootDS;

private Map<Bytes, MerkleDataSet> partitions;

/**
* Create an empty readable {@link MerkleDataCluster} instance;
*/
public MerkleDataCluster(CryptoSetting setting, Bytes keyPrefix, ExPolicyKVStorage exPolicyStorage,
VersioningKVStorage versioningStorage) {
this(null, setting, keyPrefix, exPolicyStorage, versioningStorage, false);
}

/**
* Create an {@link MerkleDataCluster} instance;
*
* @param rootHash root hash of this {@link MerkleDataCluster} instance;
* @param readonly whether read only;
*/
public MerkleDataCluster(HashDigest rootHash, CryptoSetting setting, Bytes keyPrefix,
ExPolicyKVStorage exPolicyStorage, VersioningKVStorage versioningStorage, boolean readonly) {
this.rootDS = new MerkleDataSet(rootHash, setting, keyPrefix, exPolicyStorage, versioningStorage, readonly);
}

@Override
public HashDigest getRootHash() {
return rootDS.getRootHash();
}

@Override
public boolean isUpdated() {
return rootDS.isUpdated();
}

public VersioningMap<Bytes, byte[]> getPartition(Bytes name) {
return getPartition(name, false);
}

public VersioningMap<Bytes, byte[]> getPartition(Bytes name, boolean create) {
}

public VersioningMap<Bytes, byte[]> createPartition(Bytes name) {

}

@Override
public void commit() {
// TODO Auto-generated method stub

}

@Override
public void cancel() {
// TODO Auto-generated method stub

}

}

+ 3
- 5
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleDataSet.java View File

@@ -31,11 +31,9 @@ public class MerkleDataSet implements Transactional, MerkleProvable, VersioningM
*/ */
public static final int MAX_SIZE_OF_VALUE = 4 * 1024 * 1024; public static final int MAX_SIZE_OF_VALUE = 4 * 1024 * 1024;
public static final String ORIG_KEY_SEPERATOR = LedgerConsts.KEY_SEPERATOR;
public static final Bytes SN_PREFIX = Bytes.fromString("SN" + ORIG_KEY_SEPERATOR);
public static final Bytes DATA_PREFIX = Bytes.fromString("KV" + ORIG_KEY_SEPERATOR);
public static final Bytes MERKLE_TREE_PREFIX = Bytes.fromString("MKL" + ORIG_KEY_SEPERATOR);
public static final Bytes SN_PREFIX = Bytes.fromString("SN" + LedgerConsts.KEY_SEPERATOR);
public static final Bytes DATA_PREFIX = Bytes.fromString("KV" + LedgerConsts.KEY_SEPERATOR);
public static final Bytes MERKLE_TREE_PREFIX = Bytes.fromString("MKL" + LedgerConsts.KEY_SEPERATOR);
private final Bytes snKeyPrefix; private final Bytes snKeyPrefix;
private final Bytes dataKeyPrefix; private final Bytes dataKeyPrefix;


Loading…
Cancel
Save