@Override public TableAvailability getAvailability() { if (!_facade) { return new TableAvailability(_options.getPlacement(), false); } // Facades aren't fully supported throw new UnsupportedOperationException(); }
@Override public String getTablePlacement() { return _table.getOptions().getPlacement(); } }
@Override public String getTablePlacement() { return _table.getOptions().getPlacement(); } }
@Override public TableAvailability getAvailability() { if (!_facade) { return new TableAvailability(_options.getPlacement(), false); } // Facades aren't fully supported throw new UnsupportedOperationException(); }
@Override public String getTablePlacement() { return _table.getOptions().getPlacement(); }
@Override public String getTablePlacement() { return _table.getOptions().getPlacement(); }
@Override public void create(final String name, final TableOptions options, final Map<String, ?> attributes, final Audit audit) throws TableExistsException { // Optimistically skip creating the table if it exists already so we don't thrash the ZooKeeper lock if clients // call create table repeatedly. If the table doesn't exist or is different, AstyanaxTableDAO will do this // check again for safety after obtaining the data-center-wide ZooKeeper lock. Table existingTable; try { existingTable = _delegate.get(name); if (existingTable.getOptions().getPlacement().equals(options.getPlacement()) && existingTable.getAttributes().equals(attributes)) { return; // Nothing to do } } catch (UnknownTableException ute) { // Ignore } withLock(new Runnable() { @Override public void run() { _delegate.create(name, options, attributes, audit); } }, name); }
@Override public void create(final String name, final TableOptions options, final Map<String, ?> attributes, final Audit audit) throws TableExistsException { // Optimistically skip creating the table if it exists already so we don't thrash the ZooKeeper lock if clients // call create table repeatedly. If the table doesn't exist or is different, AstyanaxTableDAO will do this // check again for safety after obtaining the data-center-wide ZooKeeper lock. Table existingTable; try { existingTable = _delegate.get(name); if (existingTable.getOptions().getPlacement().equals(options.getPlacement()) && existingTable.getAttributes().equals(attributes)) { return; // Nothing to do } } catch (UnknownTableException ute) { // Ignore } withLock(new Runnable() { @Override public void run() { _delegate.create(name, options, attributes, audit); } }, name); }
@Override public void create(String name, TableOptions options, Map<String, ?> attributes, Audit audit) { // Check that the table doesn't yet exist. Long existingUuid = _nameToUuid.get(name); if (existingUuid != null) { Table existingTable = _uuidToTable.get(existingUuid); if (existingTable.getOptions().getPlacement().equals(options.getPlacement()) && existingTable.getAttributes().equals(attributes)) { // Allow re-creating a table with no changes as a way of forcing a global cache flush. return; } else { throw new TableExistsException(format("Cannot create table that already exists: %s", name), name); } } long newUuid = Hashing.murmur3_128().hashUnencodedChars(name).asLong(); while (_uuidToTable.containsKey(newUuid) || newUuid == -1) { newUuid += 1; } _nameToUuid.put(name, newUuid); _uuidToTable.put(newUuid, new InMemoryTable(name, options, Maps.newHashMap(attributes))); }
@Override public void create(String name, TableOptions options, Map<String, ?> attributes, Audit audit) { // Check that the table doesn't yet exist. Long existingUuid = _nameToUuid.get(name); if (existingUuid != null) { Table existingTable = _uuidToTable.get(existingUuid); if (existingTable.getOptions().getPlacement().equals(options.getPlacement()) && existingTable.getAttributes().equals(attributes)) { // Allow re-creating a table with no changes as a way of forcing a global cache flush. return; } else { throw new TableExistsException(format("Cannot create table that already exists: %s", name), name); } } long newUuid = Hashing.murmur3_128().hashUnencodedChars(name).asLong(); while (_uuidToTable.containsKey(newUuid) || newUuid == -1) { newUuid += 1; } _nameToUuid.put(name, newUuid); _uuidToTable.put(newUuid, new InMemoryTable(name, options, Maps.newHashMap(attributes))); }
private TableOptions replacePlacementIfMoveInProgress(TableOptions options) { String placement = options.getPlacement(); if (_placementsUnderMove.containsKey(placement)) { return new TableOptionsBuilder().setFacades(options.getFacades()) .setPlacement(_placementsUnderMove.get(placement)).build(); } return options; }
private TableOptions replacePlacementIfMoveInProgress(TableOptions options) { String placement = options.getPlacement(); if (_placementsUnderMove.containsKey(placement)) { return new TableOptionsBuilder().setFacades(options.getFacades()) .setPlacement(_placementsUnderMove.get(placement)).build(); } return options; }
private String getPlacement(Table table, boolean useOptionsPlacement) { if (!useOptionsPlacement) { TableAvailability availability = table.getAvailability(); if (availability != null) { return availability.getPlacement(); } // If the table isn't available locally then defer to it's placement from the table options. // If the user doesn't have permission the permission check will fail. If he does the permission // check won't fail but another more informative exception will likely be thrown. } return table.getOptions().getPlacement(); } }
private String getPlacement(Table table, boolean useMasterPlacement) { if (!useMasterPlacement) { TableAvailability availability = table.getAvailability(); if (availability != null) { return availability.getPlacement(); } // If the table isn't available locally then defer to it's placement from the table options. // If the user doesn't have permission the permission check will fail. If he does the permission // check won't fail but another more informative exception will likely be thrown. } return table.getOptions().getPlacement(); } }
@Override public AnnotatedGet add(String tableName, String key) throws UnknownTableException, UnknownPlacementException { checkLegalTableName(tableName); checkNotNull(key, "key"); // The following call will throw UnknownTableException if the table doesn't currently exist. This // happens if the table was dropped prior to this call. Table table = _tableDao.get(tableName); // It's also possible that the table exists but is not available locally. This happens if the table // once had a locally available facade but the facade was since dropped. Check if this is the case and, // if so, raise UnknownPlacementException. if (table.getAvailability() == null) { throw new UnknownPlacementException("Table unavailable locally and has no local facade", table.getOptions().getPlacement(), tableName); } _keys.add(new Key(table, key)); return this; }
@Override public AnnotatedGet add(String tableName, String key) throws UnknownTableException, UnknownPlacementException { checkLegalTableName(tableName); checkNotNull(key, "key"); // The following call will throw UnknownTableException if the table doesn't currently exist. This // happens if the table was dropped prior to this call. Table table = _tableDao.get(tableName); // It's also possible that the table exists but is not available locally. This happens if the table // once had a locally available facade but the facade was since dropped. Check if this is the case and, // if so, raise UnknownPlacementException. if (table.getAvailability() == null) { throw new UnknownPlacementException("Table unavailable locally and has no local facade", table.getOptions().getPlacement(), tableName); } _keys.add(new Key(table, key)); return this; }
@PUT @Path ("_table/{table}") @Consumes (MediaType.APPLICATION_JSON) @Timed (name = "bv.emodb.sor.DataStoreResource1.createTable", absolute = true) @ApiOperation (value = "Creates a table", notes = "Returns a SuccessResponse if table is created", response = SuccessResponse.class ) public SuccessResponse createTable(@PathParam ("table") String table, @QueryParam ("options") TableOptionsParam optionParams, Map<String, Object> template, @QueryParam ("audit") AuditParam auditParam, @Context UriInfo uriInfo, @Authenticated Subject subject) { TableOptions options = getRequired(optionParams, "options"); Audit audit = getRequired(auditParam, "audit"); // Check permission for creating this table CreateTableResource resource = new CreateTableResource(table, options.getPlacement(), template); if (!subject.hasPermission(Permissions.createSorTable(resource))) { throw new UnauthorizedException(); } _dataStore.createTable(table, options, template, audit); return SuccessResponse.instance(); }
@PUT @Path("_table/{table}") @Consumes(MediaType.APPLICATION_JSON) @Timed(name = "bv.emodb.blob.BlobStoreResource1.createTable", absolute = true) @ApiOperation (value = "Creates a table.", notes = "Returns a SuccessResponse if table is created.", response = SuccessResponse.class ) public SuccessResponse createTable(@PathParam("table") String table, @QueryParam("options") TableOptionsParam optionParams, Map<String, String> attributes, @QueryParam("audit") AuditParam auditParam, @Context UriInfo uriInfo, @Authenticated Subject subject) { TableOptions options = getRequired(optionParams, "options"); Audit audit = getRequired(auditParam, "audit"); // Check permission for creating this table CreateTableResource resource = new CreateTableResource(table, options.getPlacement(), attributes); if (!subject.hasPermission(Permissions.createBlobTable(resource))) { throw new UnauthorizedException(); } _blobStore.createTable(table, options, attributes, audit); return SuccessResponse.instance(); }
private Table newTable(String name, TableOptions options, Map<String, Object> attributes, boolean available, Storage storage) { TableAvailability availability = available ? new TableAvailability(storage.getPlacement(), storage.isFacade()) : null; // Reads are performed using placement and table uuid of the specified storage. AstyanaxStorage read = newAstyanaxStorage(storage, name); // If there's a move in progress, writes go to both the regular location and the move destination. List<AstyanaxStorage> write = Lists.newArrayList(); write.add(read); // Usual case. for (Storage mirrorTo : storage.getMirrors()) { write.add(newAstyanaxStorage(mirrorTo, name)); // When a move is in progress. } // Data centers for facade = all dc in the placement - dc of the master placement. String excludePlacement = storage.isFacade() ? options.getPlacement() : null; Supplier<Collection<DataCenter>> dcSupplier = getDataCentersSupplier(storage.getPlacement(), excludePlacement); return new AstyanaxTable(name, options, attributes, availability, read, write, dcSupplier); }
private Table newTable(String name, TableOptions options, Map<String, Object> attributes, boolean available, Storage storage) { TableAvailability availability = available ? new TableAvailability(storage.getPlacement(), storage.isFacade()) : null; // Reads are performed using placement and table uuid of the specified storage. AstyanaxStorage read = newAstyanaxStorage(storage, name); // If there's a move in progress, writes go to both the regular location and the move destination. List<AstyanaxStorage> write = Lists.newArrayList(); write.add(read); // Usual case. for (Storage mirrorTo : storage.getMirrors()) { write.add(newAstyanaxStorage(mirrorTo, name)); // When a move is in progress. } // Data centers for facade = all dc in the placement - dc of the master placement. String excludePlacement = storage.isFacade() ? options.getPlacement() : null; Supplier<Collection<DataCenter>> dcSupplier = getDataCentersSupplier(storage.getPlacement(), excludePlacement); return new AstyanaxTable(name, options, attributes, availability, read, write, dcSupplier); }