@Override public GlobalQuotaSettingsImpl fetch() throws IOException { return new GlobalQuotaSettingsImpl(null, table, null, null, QuotaUtil.getTableQuota(masterServices.getConnection(), table)); } @Override
if (quotaManager != null) { if (quotaManager.isQuotaInitialized()) { Quotas quotaForTable = QuotaUtil.getTableQuota(getConnection(), tableName); if (quotaForTable != null && quotaForTable.hasSpace()) { SpaceViolationPolicy policy = quotaForTable.getSpace().getViolationPolicy();
@Override public void postDeleteTable( ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName) throws IOException { // Do nothing if quotas aren't enabled if (!quotasEnabled) { return; } final Connection conn = ctx.getEnvironment().getConnection(); Quotas quotas = QuotaUtil.getTableQuota(conn, tableName); if (quotas != null){ if (quotas.hasSpace()){ QuotaSettings settings = QuotaSettingsFactory.removeTableSpaceLimit(tableName); try (Admin admin = conn.getAdmin()) { admin.setQuota(settings); } } if (quotas.hasThrottle()){ QuotaSettings settings = QuotaSettingsFactory.unthrottleTable(tableName); try (Admin admin = conn.getAdmin()) { admin.setQuota(settings); } } } }
@Test public void testTableQuotaUtil() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); Quotas quota = Quotas.newBuilder() .setThrottle(Throttle.newBuilder() .setReqNum(ProtobufUtil.toTimedQuota(1000, TimeUnit.SECONDS, QuotaScope.MACHINE)) .setWriteNum(ProtobufUtil.toTimedQuota(600, TimeUnit.SECONDS, QuotaScope.MACHINE)) .setReadSize(ProtobufUtil.toTimedQuota(8192, TimeUnit.SECONDS, QuotaScope.MACHINE)) .build()) .build(); // Add user quota and verify it QuotaUtil.addTableQuota(this.connection, tableName, quota); Quotas resQuota = QuotaUtil.getTableQuota(this.connection, tableName); assertEquals(quota, resQuota); // Remove user quota and verify it QuotaUtil.deleteTableQuota(this.connection, tableName); resQuota = QuotaUtil.getTableQuota(this.connection, tableName); assertEquals(null, resQuota); }
@Override public Quotas fetch() throws IOException { return QuotaUtil.getTableQuota(masterServices.getConnection(), table); }
@Test public void testTableQuotaUtil() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); Quotas quota = Quotas.newBuilder() .setThrottle(Throttle.newBuilder() .setReqNum(ProtobufUtil.toTimedQuota(1000, TimeUnit.SECONDS, QuotaScope.MACHINE)) .setWriteNum(ProtobufUtil.toTimedQuota(600, TimeUnit.SECONDS, QuotaScope.MACHINE)) .setReadSize(ProtobufUtil.toTimedQuota(8192, TimeUnit.SECONDS, QuotaScope.MACHINE)) .build()) .build(); // Add user quota and verify it QuotaUtil.addTableQuota(this.connection, tableName, quota); Quotas resQuota = QuotaUtil.getTableQuota(this.connection, tableName); assertEquals(quota, resQuota); // Remove user quota and verify it QuotaUtil.deleteTableQuota(this.connection, tableName); resQuota = QuotaUtil.getTableQuota(this.connection, tableName); assertEquals(null, resQuota); }