org.apache.kylin.metadata.MetadataManager Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kylin.metadata;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.kylin.common.KylinConfig;
import org.apache.kylin.common.persistence.JsonSerializer;
import org.apache.kylin.common.persistence.RawResource;
import org.apache.kylin.common.persistence.ResourceStore;
import org.apache.kylin.common.persistence.Serializer;
import org.apache.kylin.common.restclient.Broadcaster;
import org.apache.kylin.common.restclient.CaseInsensitiveStringCache;
import org.apache.kylin.common.util.JsonUtil;
import org.apache.kylin.metadata.model.DataModelDesc;
import org.apache.kylin.metadata.model.TableDesc;
import org.apache.kylin.metadata.project.ProjectManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
/**
* Serves (and caches) metadata for Kylin instance.
*
* Also provides a ResourceStore for general purpose data persistence.
* Metadata is serialized as JSON and stored in ResourceStore.
*
* @author yangli9
*/
public class MetadataManager {
private static final Logger logger = LoggerFactory.getLogger(MetadataManager.class);
public static final Serializer TABLE_SERIALIZER = new JsonSerializer(TableDesc.class);
public static final Serializer MODELDESC_SERIALIZER = new JsonSerializer(DataModelDesc.class);
// static cached instances
private static final ConcurrentHashMap CACHE = new ConcurrentHashMap();
public static MetadataManager getInstance(KylinConfig config) {
MetadataManager r = CACHE.get(config);
if (r != null) {
return r;
}
synchronized (MetadataManager.class) {
r = CACHE.get(config);
if (r != null) {
return r;
}
try {
r = new MetadataManager(config);
CACHE.put(config, r);
if (CACHE.size() > 1) {
logger.warn("More than one singleton exist");
}
return r;
} catch (IOException e) {
throw new IllegalStateException("Failed to init MetadataManager from " + config, e);
}
}
}
public static void clearCache() {
CACHE.clear();
}
// ============================================================================
private KylinConfig config;
// table name ==> SourceTable
private CaseInsensitiveStringCache srcTableMap = new CaseInsensitiveStringCache(Broadcaster.TYPE.TABLE);
// name => value
private CaseInsensitiveStringCache
© 2015 - 2025 Weber Informatics LLC | Privacy Policy