
com.datatorrent.stram.Journal 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 com.datatorrent.stram;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.esotericsoftware.kryo.KryoException;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.google.common.collect.ImmutableMap;
import com.datatorrent.stram.plan.physical.PTContainer;
import com.datatorrent.stram.plan.physical.PTOperator;
/**
* Write ahead log for DAG changes.
* Operations need to be registered with the journal instance before writing.
* Registered prototype instances will be used to apply changes on read.
*
* @since 0.9.2
*/
public final class Journal
{
private static final Logger LOG = LoggerFactory.getLogger(Journal.class);
private enum RecoverableOperation
{
OPERATOR_STATE(PTOperator.SET_OPERATOR_STATE),
CONTAINER_STATE(PTContainer.SET_CONTAINER_STATE),
OPERATOR_PROPERTY(StreamingContainerManager.SET_OPERATOR_PROPERTY),
PHYSICAL_OPERATOR_PROPERTY(StreamingContainerManager.SET_PHYSICAL_OPERATOR_PROPERTY);
private static final Map, Integer> classToId;
static {
final ImmutableMap.Builder, Integer> builder = ImmutableMap.builder();
for (RecoverableOperation recoverableOperation : RecoverableOperation.values()) {
builder.put(recoverableOperation.operation.getClass(), recoverableOperation.ordinal());
}
classToId = builder.build();
}
private final Recoverable operation;
RecoverableOperation(Recoverable operation)
{
this.operation = operation;
}
private static RecoverableOperation get(int id)
{
return (id < values().length) ? values()[id] : null;
}
private static Integer getId(Class extends Recoverable> operationClass)
{
return classToId.get(operationClass);
}
}
public interface Recoverable
{
void read(Object object, Input in) throws KryoException;
void write(Output out) throws KryoException;
}
private final StreamingContainerManager scm;
private final AtomicReference
© 2015 - 2025 Weber Informatics LLC | Privacy Policy