org.apache.accumulo.server.tabletserver.BulkFailedCopyProcessor.java Source code

Java tutorial

Introduction

Here is the source code for org.apache.accumulo.server.tabletserver.BulkFailedCopyProcessor.java

Source

/*
 * 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.accumulo.server.tabletserver;

import java.io.IOException;

import org.apache.accumulo.core.util.CachedConfiguration;
import org.apache.accumulo.server.conf.ServerConfiguration;
import org.apache.accumulo.server.trace.TraceFileSystem;
import org.apache.accumulo.server.zookeeper.DistributedWorkQueue.Processor;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.fs.Path;
import org.apache.log4j.Logger;

/**
 * Copy failed bulk imports.
 */
public class BulkFailedCopyProcessor implements Processor {

    private static final Logger log = Logger.getLogger(BulkFailedCopyProcessor.class);

    @Override
    public Processor newProcessor() {
        return new BulkFailedCopyProcessor();
    }

    @Override
    public void process(String workID, byte[] data) {

        String paths[] = new String(data).split(",");

        Path orig = new Path(paths[0]);
        Path dest = new Path(paths[1]);
        Path tmp = new Path(dest.getParent(), dest.getName() + ".tmp");

        try {
            FileSystem fs = TraceFileSystem.wrap(org.apache.accumulo.core.file.FileUtil
                    .getFileSystem(CachedConfiguration.getInstance(), ServerConfiguration.getSiteConfiguration()));

            FileUtil.copy(fs, orig, fs, tmp, false, true, CachedConfiguration.getInstance());
            fs.rename(tmp, dest);
            log.debug("copied " + orig + " to " + dest);
        } catch (IOException ex) {
            try {
                FileSystem fs = TraceFileSystem.wrap(org.apache.accumulo.core.file.FileUtil.getFileSystem(
                        CachedConfiguration.getInstance(), ServerConfiguration.getSiteConfiguration()));

                fs.create(dest).close();
                log.warn(" marked " + dest + " failed", ex);
            } catch (IOException e) {
                log.error("Unable to create failure flag file " + dest, e);
            }
        }

    }

}