org.apache.flink.runtime.state.gemini.engine.fs.PersistenceStrategyFactory 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.flink.runtime.state.gemini.engine.fs;
import org.apache.flink.runtime.state.gemini.engine.dbms.GContext;
import org.apache.flink.runtime.state.gemini.engine.exceptions.GeminiRuntimeException;
/**
* PersistencyStrategy.
*/
public class PersistenceStrategyFactory {
/**
* PersistenceType.
*/
public enum PersistenceType {
none, asyncDfs, syncHugeToCache, bothDfsAndSyncHugeToCache;
public static PersistenceType getPersistenceType(String type) {
if (type == null || "off".equalsIgnoreCase(type) || "none".equalsIgnoreCase(type)) {
return none;
} else if ("asyncDfs".equalsIgnoreCase(type)) {
return asyncDfs;
} else if ("syncHugeToCache".equalsIgnoreCase(type)) {
return syncHugeToCache;
} else if ("bothDfsAndSyncHugeToCache".equalsIgnoreCase(type)) {
return bothDfsAndSyncHugeToCache;
}
return none;
}
}
/**
* PersistenceLevel.
*/
public enum PersistenceLevel {
flush, sync;
public static PersistenceLevel getPersistenceLevel(String type) {
if (type == null || "flush".equalsIgnoreCase(type)) {
return flush;
} else if ("sync".equalsIgnoreCase(type)) {
return sync;
}
return flush;
}
}
public static final PersistenceStrategyFactory INSTANCE = new PersistenceStrategyFactory();
public PersistenceStrategy create(GContext gContext) {
PersistenceType persistenceType = gContext.getGConfiguration().getPersistenceType();
switch (persistenceType) {
case none:
return new NonePersistence();
case asyncDfs:
return new PersistenceGroupPageToDfs(gContext);
case syncHugeToCache:
return new PersistHugePageToLocalSync(gContext);
case bothDfsAndSyncHugeToCache:
PersistenceProxy persistenceStrategy = new PersistenceProxy();
persistenceStrategy.add(new PersistenceGroupPageToDfs(gContext));
persistenceStrategy.add(new PersistHugePageToLocalSync(gContext));
return persistenceStrategy;
default:
throw new GeminiRuntimeException("error type:" + persistenceType);
}
}
}