org.apache.samza.checkpoint.azure.AzureCheckpointManager 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.samza.checkpoint.azure;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.microsoft.azure.storage.StorageException;
import com.microsoft.azure.storage.table.*;
import org.apache.samza.AzureClient;
import org.apache.samza.AzureException;
import org.apache.samza.Partition;
import org.apache.samza.SamzaException;
import org.apache.samza.checkpoint.Checkpoint;
import org.apache.samza.checkpoint.CheckpointManager;
import org.apache.samza.checkpoint.CheckpointV1;
import org.apache.samza.config.AzureConfig;
import org.apache.samza.container.TaskName;
import org.apache.samza.serializers.JsonSerdeV2;
import org.apache.samza.system.SystemStreamPartition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.Set;
/**
* Azure checkpoint manager is used to store checkpoints in a Azure Table.
* All the task checkpoints are added to the a single table named "SamzaTaskCheckpoints".
* The table entities take the following form:
*
* +-----------------+---------------------+-------------------+
* | | Serialized | |
* | TaskName | JSON SSP | Offset |
* | | | |
* +-----------------+---------------------+-------------------+
*
* Each entity have a partitionKey set as the TaskName and the rowKey set as the SSP.
*/
public class AzureCheckpointManager implements CheckpointManager {
private static final Logger LOG = LoggerFactory.getLogger(AzureCheckpointManager.class.getName());
private static final String PARTITION_KEY = "PartitionKey";
// Invalid characters in key field on Azure Table
public static final String REGEX_INVALID_KEY = ".*[#?/\\\\].*";
public static final String REGEX_TABLE_NAME = "[^A-Za-z0-9]";
public static final int MAX_WRITE_BATCH_SIZE = 100;
public static final String SYSTEM_PROP_NAME = "system";
public static final String STREAM_PROP_NAME = "stream";
public static final String PARTITION_PROP_NAME = "partition";
private final String jobTableName;
private final String storageConnectionString;
private final AzureClient azureClient;
private CloudTable cloudTable;
private final Set taskNames = new HashSet<>();
private final JsonSerdeV2
© 2015 - 2025 Weber Informatics LLC | Privacy Policy