Search in sources :

Example 1 with Fid

use of com.bonree.brfs.common.proto.FileDataProtos.Fid in project BRFS by zhangnianli.

the class Test method fid.

public static void fid() throws Exception {
    String buildStr = "rDB7ADz/6ZRmn0HImoorYbAioRdfZIIBADkwAABTCAAAARmCX9o=";
    Fid ffff = FidDecoder.build(buildStr);
    System.out.println("=====" + ffff);
}
Also used : Fid(com.bonree.brfs.common.proto.FileDataProtos.Fid)

Example 2 with Fid

use of com.bonree.brfs.common.proto.FileDataProtos.Fid in project BRFS by zhangnianli.

the class FidBuilder method getFid.

public static String getFid(FileNode node, long offset, int size) {
    Fid.Builder builder = Fid.newBuilder().setVersion(0).setCompress(0).setStorageNameCode(node.getStorageId()).setTime(node.getCreateTime()).setDuration(node.getTimeDurationMillis()).setOffset(offset).setSize(size);
    List<String> nameParts = Splitter.on("_").splitToList(node.getName());
    builder.setUuid(nameParts.get(0));
    for (int i = 1; i < nameParts.size(); i++) {
        builder.addServerId(nameParts.get(i));
    }
    Fid fid = builder.build();
    try {
        return FidEncoder.build(fid);
    } catch (Exception e) {
        LOG.error("error create FID: file[{}], offset[{}], size[{}]", node.getName(), offset, size, e);
    }
    return null;
}
Also used : Fid(com.bonree.brfs.common.proto.FileDataProtos.Fid)

Example 3 with Fid

use of com.bonree.brfs.common.proto.FileDataProtos.Fid in project BRFS by zhangnianli.

the class Test1 method main.

public static void main(String[] args) throws Exception {
    String fid = "CAAQABgAIiBiM2RkMGYxMmJmMWQ0ZjU1YWVmYWUyYWNkNjMwNzJiNyim57334SwwwM8kOgIyMDoCMjFAAEgd";
    long start = System.currentTimeMillis();
    for (int i = 0; i < 100000; i++) {
        Fid fidObj = FidDecoder.build(fid);
        // testpart base64:
        Base64.decode(fid, Base64.DEFAULT);
        // ReadObject readObject = new ReadObject();
        String str = FilePathBuilder.buildPath(fidObj, timeCache.get(new TimePair(TimeUtils.prevTimeStamp(fidObj.getTime(), fidObj.getDuration()), fidObj.getDuration())), "sn_br", 1);
    // readObject.setFilePath(FilePathBuilder.buildPath(fidObj,
    // timeCache.get(new TimePair(TimeUtils.prevTimeStamp(fidObj.getTime(), fidObj.getDuration()), fidObj.getDuration())),
    // "sn_br", 1));
    // readObject.setOffset(fidObj.getOffset());
    // readObject.setLength((int) fidObj.getSize());
    }
    System.out.println("take : " + (System.currentTimeMillis() - start));
}
Also used : Fid(com.bonree.brfs.common.proto.FileDataProtos.Fid)

Example 4 with Fid

use of com.bonree.brfs.common.proto.FileDataProtos.Fid in project BRFS by zhangnianli.

the class DefaultStorageNameStick method readData.

@Override
public InputItem readData(String fid) throws Exception {
    Fid fidObj = FidDecoder.build(fid);
    if (fidObj.getStorageNameCode() != storageId) {
        throw new IllegalAccessException("Storage name of fid is not legal!");
    }
    StringBuilder nameBuilder = new StringBuilder(fidObj.getUuid());
    String[] serverList = new String[fidObj.getServerIdCount()];
    for (int i = 0; i < fidObj.getServerIdCount(); i++) {
        String id = fidObj.getServerId(i);
        nameBuilder.append('_').append(id);
        serverList[i] = id;
    }
    try {
        // 最大尝试副本数个server
        for (int i = 0; i < serverList.length; i++) {
            ServiceMetaInfo serviceMetaInfo = selector.selectService(fidObj.getUuid(), serverList);
            if (serviceMetaInfo.getFirstServer() == null) {
                serverList[serviceMetaInfo.getReplicatPot() - 1] = null;
                continue;
            }
            Service service = serviceMetaInfo.getFirstServer();
            LOG.info("read service[{}]", service);
            ReadConnection fileReader = connectionPool.getConnection(service);
            try {
                ReadObject readObject = new ReadObject();
                readObject.setSn(storageName);
                readObject.setIndex(serviceMetaInfo.getReplicatPot());
                readObject.setTime(fidObj.getTime());
                readObject.setDuration(fidObj.getDuration());
                readObject.setFileName(nameBuilder.toString());
                // readObject.setFilePath(FilePathBuilder.buildPath(fidObj,
                // timeCache.get(new
                // TimePair(TimeUtils.prevTimeStamp(fidObj.getTime(),
                // fidObj.getDuration()), fidObj.getDuration())),
                // storageName, serviceMetaInfo.getReplicatPot()));
                readObject.setOffset(fidObj.getOffset());
                readObject.setLength((int) fidObj.getSize());
                byte[] fileContent = fileReader.read(readObject);
                return new InputItem() {

                    @Override
                    public byte[] getBytes() {
                        return fileContent;
                    }
                };
            } catch (Exception e) {
                // 使用选择的server没有读取到数据,需要进行排除
                serverList[serviceMetaInfo.getReplicatPot() - 1] = null;
                continue;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : Fid(com.bonree.brfs.common.proto.FileDataProtos.Fid) ServiceMetaInfo(com.bonree.brfs.client.route.ServiceMetaInfo) Service(com.bonree.brfs.common.service.Service) BRFSException(com.bonree.brfs.common.exception.BRFSException) IOException(java.io.IOException) InputItem(com.bonree.brfs.client.InputItem) ReadObject(com.bonree.brfs.common.net.tcp.file.ReadObject)

Aggregations

Fid (com.bonree.brfs.common.proto.FileDataProtos.Fid)4 InputItem (com.bonree.brfs.client.InputItem)1 ServiceMetaInfo (com.bonree.brfs.client.route.ServiceMetaInfo)1 BRFSException (com.bonree.brfs.common.exception.BRFSException)1 ReadObject (com.bonree.brfs.common.net.tcp.file.ReadObject)1 Service (com.bonree.brfs.common.service.Service)1 IOException (java.io.IOException)1