@Override public Properties getKeyspaceProperties(String keyspace) throws ConnectionException { KeyspaceDefinition ksDef = this.describeKeyspace(keyspace); if (ksDef == null) throw new NotFoundException(String.format("Keyspace '%s' not found", keyspace)); Properties props = new Properties(); ThriftKeyspaceDefinitionImpl thriftKsDef = (ThriftKeyspaceDefinitionImpl)ksDef; try { for (Entry<Object, Object> prop : thriftKsDef.getProperties().entrySet()) { props.setProperty((String)prop.getKey(), (String) prop.getValue()); } } catch (Exception e) { LOG.error(String.format("Error fetching properties for keyspace '%s'", keyspace)); } return props; }
@Override public Properties getKeyspaceProperties(String keyspace) throws ConnectionException { KeyspaceDefinition ksDef = this.describeKeyspace(keyspace); if (ksDef == null) throw new NotFoundException(String.format("Keyspace '%s' not found", keyspace)); Properties props = new Properties(); ThriftKeyspaceDefinitionImpl thriftKsDef = (ThriftKeyspaceDefinitionImpl)ksDef; try { for (Entry<Object, Object> prop : thriftKsDef.getProperties().entrySet()) { props.setProperty((String)prop.getKey(), (String) prop.getValue()); } } catch (Exception e) { LOG.error(String.format("Error fetching properties for keyspace '%s'", keyspace)); } return props; }
@Override public Properties getColumnFamilyProperties(String keyspace, String columnFamily) throws ConnectionException { KeyspaceDefinition ksDef = this.describeKeyspace(keyspace); ColumnFamilyDefinition cfDef = ksDef.getColumnFamily(columnFamily); if (cfDef == null) throw new NotFoundException(String.format("Column family '%s' in keyspace '%s' not found", columnFamily, keyspace)); Properties props = new Properties(); ThriftColumnFamilyDefinitionImpl thriftCfDef = (ThriftColumnFamilyDefinitionImpl)cfDef; try { for (Entry<Object, Object> prop : thriftCfDef.getProperties().entrySet()) { props.setProperty((String)prop.getKey(), (String) prop.getValue()); } } catch (Exception e) { LOG.error("Error processing column family properties"); } return props; }
@Override public Partitioner getPartitioner() throws ConnectionException { if (partitioner == null) { synchronized(this) { if (partitioner == null) { String partitionerName = this.describePartitioner(); try { partitioner = config.getPartitioner(partitionerName); LOG.info(String.format("Detected partitioner %s for keyspace %s", partitionerName, ksName)); } catch (Exception e) { throw new NotFoundException("Unable to determine partitioner " + partitionerName, e); } } } } return partitioner; }
public String readUniqueColumn() throws Exception { String column = null; for (Entry<String, Long> entry : lock.readLockColumns().entrySet()) { if (entry.getValue() == 0) { if (column == null) { column = entry.getKey().substring(lock.getPrefix().length()); } else { throw new IllegalStateException("Key has multiple locks"); } } } if (column == null) throw new NotFoundException("Unique column not found for " + lock.getKey()); return column; }
@Override public Properties getColumnFamilyProperties(String keyspace, String columnFamily) throws ConnectionException { KeyspaceDefinition ksDef = this.describeKeyspace(keyspace); ColumnFamilyDefinition cfDef = ksDef.getColumnFamily(columnFamily); if (cfDef == null) throw new NotFoundException(String.format("Column family '%s' in keyspace '%s' not found", columnFamily, keyspace)); Properties props = new Properties(); ThriftColumnFamilyDefinitionImpl thriftCfDef = (ThriftColumnFamilyDefinitionImpl)cfDef; try { for (Entry<Object, Object> prop : thriftCfDef.getProperties().entrySet()) { props.setProperty((String)prop.getKey(), (String) prop.getValue()); } } catch (Exception e) { LOG.error("Error processing column family properties"); } return props; }
public String readUniqueColumn() throws Exception { String column = null; for (Entry<String, Long> entry : lock.readLockColumns().entrySet()) { if (entry.getValue() == 0) { if (column == null) { column = entry.getKey().substring(lock.getPrefix().length()); } else { throw new IllegalStateException("Key has multiple locks"); } } } if (column == null) throw new NotFoundException("Unique column not found for " + lock.getKey()); return column; }
@Override public Partitioner getPartitioner() throws ConnectionException { if (partitioner == null) { synchronized(this) { if (partitioner == null) { String partitionerName = this.describePartitioner(); try { partitioner = config.getPartitioner(partitionerName); LOG.info(String.format("Detected partitioner %s for keyspace %s", partitionerName, ksName)); } catch (Exception e) { throw new NotFoundException("Unable to determine partitioner " + partitionerName, e); } } } } return partitioner; }
@Override public Properties getKeyspaceProperties() throws ConnectionException { KeyspaceDefinition ksDef = this.describeKeyspace(); if (ksDef == null) throw new NotFoundException(String.format("Keyspace '%s' not found", getKeyspaceName())); Properties props = new Properties(); ThriftKeyspaceDefinitionImpl thriftKsDef = (ThriftKeyspaceDefinitionImpl)ksDef; try { for (Entry<Object, Object> prop : thriftKsDef.getProperties().entrySet()) { props.setProperty((String)prop.getKey(), (String) prop.getValue()); } } catch (Exception e) { LOG.error(String.format("Error fetching properties for keyspace '%s'", getKeyspaceName())); } return props; }
@Override public Properties getKeyspaceProperties() throws ConnectionException { KeyspaceDefinition ksDef = this.describeKeyspace(); if (ksDef == null) throw new NotFoundException(String.format("Keyspace '%s' not found", getKeyspaceName())); Properties props = new Properties(); ThriftKeyspaceDefinitionImpl thriftKsDef = (ThriftKeyspaceDefinitionImpl)ksDef; try { for (Entry<Object, Object> prop : thriftKsDef.getProperties().entrySet()) { props.setProperty((String)prop.getKey(), (String) prop.getValue()); } } catch (Exception e) { LOG.error(String.format("Error fetching properties for keyspace '%s'", getKeyspaceName())); } return props; }
@Override public Properties getColumnFamilyProperties(String columnFamily) throws ConnectionException { KeyspaceDefinition ksDef = this.describeKeyspace(); ColumnFamilyDefinition cfDef = ksDef.getColumnFamily(columnFamily); if (cfDef == null) throw new NotFoundException(String.format("Column family '%s' in keyspace '%s' not found", columnFamily, getKeyspaceName())); Properties props = new Properties(); ThriftColumnFamilyDefinitionImpl thriftCfDef = (ThriftColumnFamilyDefinitionImpl)cfDef; try { for (Entry<Object, Object> prop : thriftCfDef.getProperties().entrySet()) { props.setProperty((String)prop.getKey(), (String) prop.getValue()); } } catch (Exception e) { LOG.error("Error processing column family properties"); } return props; } }
@Override public Properties getColumnFamilyProperties(String columnFamily) throws ConnectionException { KeyspaceDefinition ksDef = this.describeKeyspace(); ColumnFamilyDefinition cfDef = ksDef.getColumnFamily(columnFamily); if (cfDef == null) throw new NotFoundException(String.format("Column family '%s' in keyspace '%s' not found", columnFamily, getKeyspaceName())); Properties props = new Properties(); ThriftColumnFamilyDefinitionImpl thriftCfDef = (ThriftColumnFamilyDefinitionImpl)cfDef; try { for (Entry<Object, Object> prop : thriftCfDef.getProperties().entrySet()) { props.setProperty((String)prop.getKey(), (String) prop.getValue()); } } catch (Exception e) { LOG.error("Error processing column family properties"); } return props; } }
@Override public Properties getColumnFamilyProperties(String columnFamily) throws ConnectionException { KeyspaceDefinition ksDef = this.describeKeyspace(); ColumnFamilyDefinition cfDef = ksDef.getColumnFamily(columnFamily); if (cfDef == null) throw new NotFoundException(String.format("Column family '%s' in keyspace '%s' not found", columnFamily, getKeyspaceName())); try { return cfDef.getProperties(); } catch (Exception e) { throw new RuntimeException(); } }
throw new NotFoundException(this.key.toString() + " has no uniquness lock");
throw new NotFoundException(this.key.toString() + " has no uniquness lock");
@Override public void deleteObject(String objectName, Integer chunkCount) throws Exception, NotFoundException { if (chunkCount == null) { ObjectMetadata attr = readMetadata(objectName); if (attr.getChunkCount() == null) throw new NotFoundException("Object not found :" + objectName); chunkCount = attr.getChunkCount(); } MutationBatch m = keyspace.prepareMutationBatch().withRetryPolicy(retryPolicy); for (int i = 0; i < chunkCount; i++) { m.withRow(cf, getRowKey(objectName, i)).delete(); } m.withRow(cf, objectName).delete(); m.execute(); }
@Override public void deleteObject(String objectName, Integer chunkCount) throws Exception, NotFoundException { if (chunkCount == null) { ObjectMetadata attr = readMetadata(objectName); if (attr.getChunkCount() == null) throw new NotFoundException("Object not found :" + objectName); chunkCount = attr.getChunkCount(); } MutationBatch m = keyspace.prepareMutationBatch().withRetryPolicy(retryPolicy); for (int i = 0; i < chunkCount; i++) { m.withRow(cf, getRowKey(objectName, i)).delete(); } m.withRow(cf, objectName).delete(); m.execute(); }
@Override public ObjectMetadata readMetadata(String objectName) throws Exception, NotFoundException { ColumnList<String> columns = keyspace.prepareQuery(cf).getKey(objectName).execute().getResult(); if (columns.isEmpty()) { throw new NotFoundException(objectName); } return new ObjectMetadata().setObjectSize(columns.getLongValue(getColumnName(Columns.OBJECTSIZE), null)) .setChunkSize(columns.getIntegerValue(getColumnName(Columns.CHUNKSIZE), null)) .setChunkCount(columns.getIntegerValue(getColumnName(Columns.CHUNKCOUNT), null)) .setAttributes(columns.getStringValue(getColumnName(Columns.ATTRIBUTES), null)); }
@Override public ObjectMetadata readMetadata(String objectName) throws Exception, NotFoundException { ColumnList<String> columns = keyspace.prepareQuery(cf).getKey(objectName).execute().getResult(); if (columns.isEmpty()) { throw new NotFoundException(objectName); } return new ObjectMetadata().setObjectSize(columns.getLongValue(getColumnName(Columns.OBJECTSIZE), null)) .setChunkSize(columns.getIntegerValue(getColumnName(Columns.CHUNKSIZE), null)) .setChunkCount(columns.getIntegerValue(getColumnName(Columns.CHUNKCOUNT), null)) .setAttributes(columns.getStringValue(getColumnName(Columns.ATTRIBUTES), null)); }