MCPcopy Create free account
hub / github.com/apache/impala / Db

Class Db

fe/src/main/java/org/apache/impala/catalog/Db.java:76–660  ·  view source on GitHub ↗

Internal representation of db-related metadata. Owned by Catalog instance. Not thread safe. Tables are stored in a map from the table name to the table object. They may be loaded 'eagerly' at construction or 'lazily' on first reference. Tables are accessed via getTable which may trigger a metadata

Source from the content-addressed store, hash-verified

74 *
75 */
76public class Db extends CatalogObjectImpl implements FeDb {
77 private static final Logger LOG = LoggerFactory.getLogger(Db.class);
78 // TODO: We should have a consistent synchronization model for Db and Table
79 // Right now, we synchronize functions and thriftDb_ object in-place and do
80 // not take read lock on catalogVersion. See IMPALA-8366 for details
81 private final AtomicReference<TDatabase> thriftDb_ = new AtomicReference<>();
82
83 public static final String FUNCTION_INDEX_PREFIX = "impala_registered_function_";
84
85 // Name of the standard system DB. Also used by Hive MetaStore.
86 public static final String SYS = "sys";
87
88 // Hive metastore imposes a limit of 4000 bytes on the key and value strings
89 // in DB parameters map. We need ensure that this limit isn't crossed
90 // while serializing functions to the metastore.
91 private static final int HIVE_METASTORE_DB_PARAM_LIMIT_BYTES = 4000;
92
93 // Table metadata cache.
94 private final CatalogObjectCache<Table> tableCache_;
95
96 // All of the registered user functions. The key is the user facing name (e.g. "myUdf"),
97 // and the values are all the overloaded variants (e.g. myUdf(double), myUdf(string))
98 // This includes both UDFs and UDAs. Updates are made thread safe by synchronizing
99 // on this map. When a new Db object is initialized, this list is updated with the
100 // UDF/UDAs already persisted, if any, in the metastore DB. Functions are sorted in a
101 // canonical order defined by FunctionResolutionOrder.
102 private final Map<String, List<Function>> functions_;
103
104 // If true, this database is an Impala system database.
105 // (e.g. can't drop it, can't add tables to it, etc).
106 private boolean isSystemDb_ = false;
107
108 // tracks the in-flight metastore events for this db
109 // Also used as a monitor object to synchronize access to it to avoid blocking on table
110 // lock during self-event check. If both this and dbLock_ or catalog version lock are
111 // taken, inFlightEvents_ must be the last to avoid deadlock.
112 private final InFlightEvents inFlightEvents_ = new InFlightEvents();
113
114 // lock to make sure modifications to the Db object are atomically done along with
115 // its associated HMS operation (eg. alterDbOwner or commentOnDb)
116 private final ReentrantLock dbLock_ = new ReentrantLock();
117
118 // if this Db is created by catalogd and if events processing is ACTIVE then
119 // this field represents the event id pertaining to the creation of this database
120 // in hive metastore. Defaults to -1 for already existing databases or if events
121 // processing is disabled.
122 private long createEventId_ = -1;
123
124 // this field represents the last event id in metastore upto which this db is synced
125 // It is used if the flag sync_to_latest_event_on_ddls is set to true.
126 // Making it as volatile so that read and write of this variable are thread safe.
127 // As an example, EventProcessor can check if it needs to process a db event or not
128 // by reading this flag and without acquiring read lock on db object
129 private volatile long lastSyncedEventId_ = -1;
130
131 // Flag used by CatalogServiceCatalog to mark if this Db is already removed or not.
132 // Should only be used by CatalogServiceCatalog.
133 private volatile boolean isRemoved_ = false;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected