1 // This file is part of OpenTSDB. 2 // Copyright (C) 2016 The OpenTSDB Authors. 3 // 4 // This program is free software: you can redistribute it and/or modify it 5 // under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 2.1 of the License, or (at your 7 // option) any later version. This program is distributed in the hope that it 8 // will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 // General Public License for more details. You should have received a copy 11 // of the GNU Lesser General Public License along with this program. If not, 12 // see <http://www.gnu.org/licenses/>. 13 package net.opentsdb.meta; 14 15 import com.stumbleupon.async.Deferred; 16 17 import net.opentsdb.core.TSDB; 18 import net.opentsdb.stats.StatsCollector; 19 20 /** 21 * This is a first stab at a meta data cache. Initially it only handles 22 * incrementing TSUID counters in a local database. The class will then 23 * periodically sync the local counter cache with HBase and generate TSMeta 24 * objects if necessary. This keeps us from having to maintain thousands or 25 * millions of callback objects in memory while we wait for individual atomic 26 * increments per data point. 27 * @since 2.3 28 */ 29 public abstract class MetaDataCache { 30 31 /** 32 * Called by TSDB to initialize the plugin 33 * Implementations are responsible for setting up any IO they need as well 34 * as starting any required background threads. 35 * <b>Note:</b> Implementations should throw exceptions if they can't start 36 * up properly. The TSD will then shutdown so the operator can fix the 37 * problem. Please use IllegalArgumentException for configuration issues. 38 * @param tsdb The parent TSDB object 39 * @throws IllegalArgumentException if required configuration parameters are 40 * missing 41 * @throws Exception if something else goes wrong 42 */ initialize(final TSDB tsdb)43 public abstract void initialize(final TSDB tsdb); 44 45 /** 46 * Called when the TSD is shutting down to gracefully flush any buffers or 47 * close open connections. 48 */ shutdown()49 public abstract Deferred<Object> shutdown(); 50 51 /** 52 * Should return the version of this plugin in the format: 53 * MAJOR.MINOR.MAINT, e.g. 2.0.1. The MAJOR version should match the major 54 * version of OpenTSDB the plugin is meant to work with. 55 * @return A version string used to log the loaded version 56 */ version()57 public abstract String version(); 58 59 /** 60 * Called by the TSD when a request for statistics collection has come in. The 61 * implementation may provide one or more statistics. If no statistics are 62 * available for the implementation, simply stub the method. 63 * @param collector The collector used for emitting statistics 64 */ collectStats(final StatsCollector collector)65 public abstract void collectStats(final StatsCollector collector); 66 67 /** 68 * Increments the given TSUID in the cache by 1 69 * @param tsuid The tsuid to increment 70 */ increment(final byte[] tsuid)71 public abstract void increment(final byte[] tsuid); 72 73 } 74