001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to you under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.hadoop.hbase.quotas; 018 019import java.io.IOException; 020import org.apache.hadoop.hbase.TableName; 021import org.apache.hadoop.hbase.client.Connection; 022import org.apache.hadoop.hbase.client.Put; 023import org.apache.hadoop.hbase.client.Table; 024import org.apache.yetus.audience.InterfaceAudience; 025import org.slf4j.Logger; 026import org.slf4j.LoggerFactory; 027 028/** 029 * A {@link SpaceQuotaSnapshotNotifier} which uses the hbase:quota table. 030 */ 031@InterfaceAudience.Private 032public class TableSpaceQuotaSnapshotNotifier implements SpaceQuotaSnapshotNotifier { 033 private static final Logger LOG = LoggerFactory.getLogger(TableSpaceQuotaSnapshotNotifier.class); 034 035 private Connection conn; 036 037 @Override 038 public void transitionTable( 039 TableName tableName, SpaceQuotaSnapshot snapshot) throws IOException { 040 final Put p = QuotaTableUtil.createPutForSpaceSnapshot(tableName, snapshot); 041 try (Table quotaTable = conn.getTable(QuotaTableUtil.QUOTA_TABLE_NAME)) { 042 if (LOG.isTraceEnabled()) { 043 LOG.trace("Persisting a space quota snapshot " + snapshot + " for " + tableName); 044 } 045 quotaTable.put(p); 046 } 047 } 048 049 @Override 050 public void initialize(Connection conn) { 051 this.conn = conn; 052 } 053}