Search in sources :

Example 1 with GSException

use of com.toshiba.mwcloud.gs.GSException in project YCSB by brianfrankcooper.

the class GridDBClient method update.

public Status update(String table, String key, Map<String, ByteIterator> values) {
    try {
        Object rowKey = makeRowKey(key);
        String containerKey = makeContainerKey(key);
        final Container<Object, Row> container = store.getContainer(containerKey);
        if (container == null) {
            LOGGER.severe("[ERROR]getCollection " + containerKey + " in update()");
            return Status.ERROR;
        }
        Row targetRow = container.get(rowKey);
        if (targetRow == null) {
            LOGGER.severe("[ERROR]get(rowKey) in update()");
            return Status.ERROR;
        }
        int setCount = 0;
        for (int i = 1; i < containerInfo.getColumnCount() && setCount < values.size(); i++) {
            containerInfo.getColumnInfo(i).getName();
            ByteIterator byteIterator = values.get(containerInfo.getColumnInfo(i).getName());
            if (byteIterator != null) {
                Object value = makeValue(byteIterator);
                targetRow.setValue(i, value);
                setCount++;
            }
        }
        if (setCount != values.size()) {
            LOGGER.severe("Error setCount = " + setCount);
            return Status.ERROR;
        }
        container.put(targetRow);
        return Status.OK;
    } catch (GSException e) {
        LOGGER.severe("Exception: " + e.getMessage());
        return Status.ERROR;
    }
}
Also used : ByteIterator(site.ycsb.ByteIterator) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) Row(com.toshiba.mwcloud.gs.Row) GSException(com.toshiba.mwcloud.gs.GSException)

Example 2 with GSException

use of com.toshiba.mwcloud.gs.GSException in project YCSB by brianfrankcooper.

the class GridDBClient method insert.

public Status insert(String table, String key, Map<String, ByteIterator> values) {
    try {
        Object rowKey = makeRowKey(key);
        String containerKey = makeContainerKey(key);
        final Container<Object, Row> container = store.getContainer(containerKey);
        if (container == null) {
            LOGGER.severe("[ERROR]getCollection " + containerKey + " in insert()");
        }
        Row row = container.createRow();
        row.setValue(ROW_KEY_COLUMN_POS, rowKey);
        for (int i = 1; i < containerInfo.getColumnCount(); i++) {
            ByteIterator byteIterator = values.get(containerInfo.getColumnInfo(i).getName());
            Object value = makeValue(byteIterator);
            row.setValue(i, value);
        }
        container.put(row);
    } catch (GSException e) {
        LOGGER.severe("Exception: " + e.getMessage());
        return Status.ERROR;
    }
    return Status.OK;
}
Also used : ByteIterator(site.ycsb.ByteIterator) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) Row(com.toshiba.mwcloud.gs.Row) GSException(com.toshiba.mwcloud.gs.GSException)

Example 3 with GSException

use of com.toshiba.mwcloud.gs.GSException in project YCSB by brianfrankcooper.

the class GridDBClientTest method setUp.

/**
 * Create properties for configuration to get client
 * Create data table to test
 */
@Before
public void setUp() throws Exception {
    Properties p = new Properties();
    p.setProperty("notificationAddress", NOTIFICATION_ADDR);
    p.setProperty("notificationPort", NOTIFICATION_PORT);
    p.setProperty("clusterName", CLUSTER_NAME);
    p.setProperty("userName", USER_NAME);
    p.setProperty("user", USER_NAME);
    p.setProperty("password", PASS);
    p.setProperty("fieldcount", String.valueOf(FIELD_COUNT));
    p.setProperty("fieldlength", FIELD_LENGTH);
    Measurements.setProperties(p);
    final CoreWorkload workload = new CoreWorkload();
    workload.init(p);
    getDB(p);
    // Create data table to test
    // List of columns
    List<ColumnInfo> columnInfoList = new ArrayList<ColumnInfo>();
    ColumnInfo keyInfo = new ColumnInfo("key", GSType.STRING);
    columnInfoList.add(keyInfo);
    for (int i = 0; i < FIELD_COUNT; i++) {
        String columnName = String.format(VALUE_COLUMN_NAME_PREFIX + "%d", i);
        ColumnInfo info = new ColumnInfo(columnName, GSType.STRING);
        columnInfoList.add(info);
    }
    containerInfo = new ContainerInfo(null, ContainerType.COLLECTION, columnInfoList, true);
    try {
        GridStoreFactory.getInstance().setProperties(p);
        store = GridStoreFactory.getInstance().getGridStore(p);
        store.putContainer(TEST_TABLE, containerInfo, false);
    } catch (GSException e) {
        e.printStackTrace();
        throw new DBException();
    }
}
Also used : DBException(site.ycsb.DBException) CoreWorkload(site.ycsb.workloads.CoreWorkload) ArrayList(java.util.ArrayList) ContainerInfo(com.toshiba.mwcloud.gs.ContainerInfo) ColumnInfo(com.toshiba.mwcloud.gs.ColumnInfo) Properties(java.util.Properties) GSException(com.toshiba.mwcloud.gs.GSException) Before(org.junit.Before)

Example 4 with GSException

use of com.toshiba.mwcloud.gs.GSException in project YCSB by brianfrankcooper.

the class GridDBClient method read.

public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
    try {
        Object rowKey = makeRowKey(key);
        String containerKey = makeContainerKey(key);
        final Container<Object, Row> container = store.getContainer(containerKey);
        if (container == null) {
            LOGGER.severe("[ERROR]getCollection " + containerKey + " in read()");
            return Status.ERROR;
        }
        Row targetRow = container.get(rowKey);
        if (targetRow == null) {
            LOGGER.severe("[ERROR]get(rowKey) in read()");
            return Status.ERROR;
        }
        for (int i = 1; i < containerInfo.getColumnCount(); i++) {
            result.put(containerInfo.getColumnInfo(i).getName(), new ByteArrayByteIterator(targetRow.getValue(i).toString().getBytes()));
        }
        return Status.OK;
    } catch (GSException e) {
        LOGGER.severe("Exception: " + e.getMessage());
        return Status.ERROR;
    }
}
Also used : ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) Row(com.toshiba.mwcloud.gs.Row) GSException(com.toshiba.mwcloud.gs.GSException)

Example 5 with GSException

use of com.toshiba.mwcloud.gs.GSException in project YCSB by brianfrankcooper.

the class GridDBClient method init.

public void init() throws DBException {
    LOGGER.info("GridDBClient");
    final Properties props = getProperties();
    notificationAddress = props.getProperty("notificationAddress");
    notificationPort = props.getProperty("notificationPort");
    notificationMember = props.getProperty("notificationMember");
    clusterName = props.getProperty("clusterName");
    userName = props.getProperty("userName");
    password = props.getProperty("password");
    containerPrefix = props.getProperty("table", "usertable") + "@";
    String fieldcount = props.getProperty("fieldcount");
    String fieldlength = props.getProperty("fieldlength");
    LOGGER.info("notificationAddress=" + notificationAddress + " notificationPort=" + notificationPort + " notificationMember=" + notificationMember);
    LOGGER.info("clusterName=" + clusterName + " userName=" + userName);
    LOGGER.info("fieldcount=" + fieldcount + " fieldlength=" + fieldlength);
    final Properties gridstoreProp = new Properties();
    if (clusterName == null || userName == null || password == null) {
        LOGGER.severe("[ERROR] clusterName or userName or password argument not specified");
        throw new DBException();
    }
    if (fieldcount == null || fieldlength == null) {
        LOGGER.severe("[ERROR] fieldcount or fieldlength argument not specified");
        throw new DBException();
    } else {
        if (!fieldcount.equals(String.valueOf(FIELD_NUM)) || !fieldlength.equals("100")) {
            LOGGER.severe("[ERROR] Invalid argment: fieldcount or fieldlength");
            throw new DBException();
        }
    }
    if (notificationAddress != null) {
        if (notificationPort == null) {
            LOGGER.severe("[ERROR] notificationPort argument not specified");
            throw new DBException();
        }
        // (A)multicast method
        gridstoreProp.setProperty("notificationAddress", notificationAddress);
        gridstoreProp.setProperty("notificationPort", notificationPort);
    } else if (notificationMember != null) {
        // (B)fixed list method
        gridstoreProp.setProperty("notificationMember", notificationMember);
    } else {
        LOGGER.severe("[ERROR] notificationAddress and notificationMember argument not specified");
        throw new DBException();
    }
    gridstoreProp.setProperty("clusterName", clusterName);
    gridstoreProp.setProperty("user", userName);
    gridstoreProp.setProperty("password", password);
    gridstoreProp.setProperty("containerCacheSize", String.valueOf(DEFAULT_CACHE_CONTAINER_NUM));
    List<ColumnInfo> columnInfoList = new ArrayList<ColumnInfo>();
    ColumnInfo keyInfo = new ColumnInfo("key", SCHEMA_TYPE);
    columnInfoList.add(keyInfo);
    for (int i = 0; i < FIELD_NUM; i++) {
        String columnName = String.format(VALUE_COLUMN_NAME_PREFIX + "%d", i);
        ColumnInfo info = new ColumnInfo(columnName, SCHEMA_TYPE);
        columnInfoList.add(info);
    }
    containerInfo = new ContainerInfo(null, ContainerType.COLLECTION, columnInfoList, true);
    try {
        GridStoreFactory.getInstance().setProperties(gridstoreProp);
        store = GridStoreFactory.getInstance().getGridStore(gridstoreProp);
        PartitionController controller = store.getPartitionController();
        numContainer = controller.getPartitionCount();
        for (int k = 0; k < numContainer; k++) {
            String name = containerPrefix + k;
            store.putContainer(name, containerInfo, false);
        }
    } catch (GSException e) {
        LOGGER.severe("Exception: " + e.getMessage());
        throw new DBException();
    }
    LOGGER.info("numContainer=" + numContainer + " containerCasheSize=" + String.valueOf(DEFAULT_CACHE_CONTAINER_NUM));
}
Also used : DBException(site.ycsb.DBException) ArrayList(java.util.ArrayList) ContainerInfo(com.toshiba.mwcloud.gs.ContainerInfo) ColumnInfo(com.toshiba.mwcloud.gs.ColumnInfo) Properties(java.util.Properties) GSException(com.toshiba.mwcloud.gs.GSException) PartitionController(com.toshiba.mwcloud.gs.PartitionController)

Aggregations

GSException (com.toshiba.mwcloud.gs.GSException)5 Row (com.toshiba.mwcloud.gs.Row)3 ByteArrayByteIterator (site.ycsb.ByteArrayByteIterator)3 ColumnInfo (com.toshiba.mwcloud.gs.ColumnInfo)2 ContainerInfo (com.toshiba.mwcloud.gs.ContainerInfo)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 ByteIterator (site.ycsb.ByteIterator)2 DBException (site.ycsb.DBException)2 PartitionController (com.toshiba.mwcloud.gs.PartitionController)1 Before (org.junit.Before)1 CoreWorkload (site.ycsb.workloads.CoreWorkload)1