Thread safe Catalog for an Impalad. The Impalad catalog can be updated either via a StateStore heartbeat or by directly applying the result of a catalog operation to the CatalogCache. All updates are applied using the updateCatalog() function. Table metadata is loaded lazily. The CatalogServer init
| 87 | * service has been started, in which case a full topic update is required. |
| 88 | */ |
| 89 | public class ImpaladCatalog extends Catalog implements FeCatalog { |
| 90 | private static final Logger LOG = LoggerFactory.getLogger(ImpaladCatalog.class); |
| 91 | // The last known Catalog Service ID. If the ID changes, it indicates the CatalogServer |
| 92 | // has restarted. |
| 93 | private TUniqueId catalogServiceId_ = Catalog.INITIAL_CATALOG_SERVICE_ID; |
| 94 | |
| 95 | // The catalog version received in the last StateStore heartbeat. It is guaranteed |
| 96 | // all objects in the catalog have at a minimum, this version. Because updates may |
| 97 | // be applied out of band of a StateStore heartbeat, it is possible the catalog |
| 98 | // contains some objects > than this version. |
| 99 | private AtomicLong lastSyncedCatalogVersion_ = |
| 100 | new AtomicLong(Catalog.INITIAL_CATALOG_VERSION); |
| 101 | |
| 102 | // Tracks modifications to this Impalad's catalog from direct updates to the cache. |
| 103 | private final CatalogDeltaLog catalogDeltaLog_ = new CatalogDeltaLog(); |
| 104 | |
| 105 | // Object that is used to synchronize on and signal when a catalog update is received. |
| 106 | private final Object catalogUpdateEventNotifier_ = new Object(); |
| 107 | |
| 108 | private final AtomicReference<? extends AuthorizationChecker> authzChecker_; |
| 109 | |
| 110 | public ImpaladCatalog(AtomicReference<? extends AuthorizationChecker> authzChecker) { |
| 111 | super(); |
| 112 | authzChecker_ = authzChecker; |
| 113 | addDb(BuiltinsDb.getInstance()); |
| 114 | // Ensure the contents of the CatalogObjectVersionSet instance are cleared when a |
| 115 | // new instance of ImpaladCatalog is created (see IMPALA-6486). |
| 116 | CatalogObjectVersionSet.INSTANCE.clear(); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Utility class for sequencing the order in which a set of updated catalog objects |
| 121 | * need to be applied to the catalog in order to satisfy referential constraints. |
| 122 | * |
| 123 | * If one type of object refers to another type of object, it needs to be added |
| 124 | * after it and deleted before it. |
| 125 | */ |
| 126 | public static class ObjectUpdateSequencer { |
| 127 | private final ArrayDeque<TCatalogObject> updatedObjects = new ArrayDeque<>(); |
| 128 | private final ArrayDeque<TCatalogObject> deletedObjects = new ArrayDeque<>(); |
| 129 | |
| 130 | public void add(TCatalogObject obj, boolean isDeleted) { |
| 131 | if (!isDeleted) { |
| 132 | // Update top-level objects first. |
| 133 | if (isTopLevelCatalogObject(obj)) { |
| 134 | updatedObjects.addFirst(obj); |
| 135 | } else { |
| 136 | updatedObjects.addLast(obj); |
| 137 | } |
| 138 | } else { |
| 139 | // Remove low-level objects first. |
| 140 | if (isTopLevelCatalogObject(obj)) { |
| 141 | deletedObjects.addLast(obj); |
| 142 | } else { |
| 143 | deletedObjects.addFirst(obj); |
| 144 | } |
| 145 | } |
| 146 | } |
nothing calls this directly
no outgoing calls
no test coverage detected