Package org.apache.hadoop.io.SequenceFile

Examples of org.apache.hadoop.io.SequenceFile.Reader


        log.info("Openning local log " + file.getAbsolutePath());

        Path localWal = new Path(file.toURI());
        FileSystem localFs = FileSystem.getLocal(fs.getConf());
       
        @SuppressWarnings("deprecation")
        Reader reader = new SequenceFile.Reader(localFs, localWal, localFs.getConf());
        // Reader reader = new SequenceFile.Reader(localFs.getConf(), SequenceFile.Reader.file(localWal));
        Path tmp = new Path(options.destination + "/" + name + ".copy");
        FSDataOutputStream writer = fs.create(tmp);
        while (reader.next(key, value)) {
          try {
            key.write(writer);
            value.write(writer);
          } catch (EOFException ex) {
            break;
          }
        }
        writer.close();
        reader.close();
        fs.rename(tmp, new Path(tmp.getParent(), name));

        if (options.deleteLocal) {
          if (file.delete()) {
            log.info("Copied and deleted: " + name);
View Full Code Here


    SortedSet<FileStatus> existing = new TreeSet<FileStatus>(Arrays.asList(listStatus));
    if (existing.isEmpty()) {
      return;
    }
    FileStatus last = existing.last();
    Reader reader = new SequenceFile.Reader(fileSystem, last.getPath(), _configuration);
    Text key = new Text();
    LongWritable value = new LongWritable();
    while (reader.next(key, value)) {
      String name = key.toString();
      long gen = value.get();
      _namesToGenerations.put(name, gen);
      Set<String> names = _generationsToNames.get(gen);
      if (names == null) {
        names = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
        _generationsToNames.put(gen, names);
      }
      names.add(name);
    }
    reader.close();
    cleanupOldFiles();
  }
View Full Code Here

        Path dest = new Path(fullyQualifiedFileName + ".recovered");
        log.debug("Sorting log file to DSF " + dest);
        fs.mkdirs(dest);
        int part = 0;
       
        Reader reader = new SequenceFile.Reader(local, new Path(findLocalFilename(localLog)), fs.getConf());
        try {
          final ArrayList<Pair<LogFileKey,LogFileValue>> kv = new ArrayList<Pair<LogFileKey,LogFileValue>>();
          long memorySize = 0;
          while (true) {
            final long position = reader.getPosition();
            final LogFileKey key = new LogFileKey();
            final LogFileValue value = new LogFileValue();
            try {
              if (!reader.next(key, value))
                break;
            } catch (EOFException e) {
              log.warn("Unexpected end of file reading write ahead log " + localLog);
              break;
            }
            kv.add(new Pair<LogFileKey,LogFileValue>(key, value));
            memorySize += reader.getPosition() - position;
            if (memorySize > SORT_BUFFER_SIZE) {
              writeSortedEntries(dest, part++, kv);
              kv.clear();
              memorySize = 0;
            }
          }

          if (!kv.isEmpty())
            writeSortedEntries(dest, part++, kv);
          fs.create(new Path(dest, "finished")).close();
        } finally {
          reader.close();
        }
      }
     
      private void writeSortedEntries(Path dest, int part, final List<Pair<LogFileKey,LogFileValue>> kv) throws IOException {
        String path = dest + String.format("/part-r-%05d", part);
        log.debug("Writing partial log file to DSF " + path);
        log.debug("Sorting");
        Span span = Trace.start("Logger sort");
        span.data("logfile", dest.getName());
        Collections.sort(kv, new Comparator<Pair<LogFileKey,LogFileValue>>() {
          @Override
          public int compare(Pair<LogFileKey,LogFileValue> o1, Pair<LogFileKey,LogFileValue> o2) {
            return o1.getFirst().compareTo(o2.getFirst());
          }
        });
        span.stop();
        span = Trace.start("Logger write");
        span.data("logfile", dest.getName());
        MapFile.Writer writer = new MapFile.Writer(fs.getConf(), fs, path, LogFileKey.class, LogFileValue.class);
        short replication = (short) acuConf.getCount(Property.LOGGER_RECOVERY_FILE_REPLICATION);
        fs.setReplication(new Path(path + "/" + MapFile.DATA_FILE_NAME), replication);
        fs.setReplication(new Path(path + "/" + MapFile.INDEX_FILE_NAME), replication);
        try {
          for (Pair<LogFileKey,LogFileValue> entry : kv)
            writer.append(entry.getFirst(), entry.getSecond());
        } finally {
          writer.close();
          span.stop();
        }
      }
     
      private void copyLog(final String localLog, final String fullyQualifiedFileName) throws IOException {
        Path dest = new Path(fullyQualifiedFileName + ".copy");
        log.debug("Copying log file to DSF " + dest);
        fs.delete(dest, true);
        LogFileKey key = new LogFileKey();
        LogFileValue value = new LogFileValue();
        Writer writer = null;
        Reader reader = null;
        try {
          short replication = (short) acuConf.getCount(Property.LOGGER_RECOVERY_FILE_REPLICATION);
          writer = SequenceFile.createWriter(fs, fs.getConf(), dest, LogFileKey.class, LogFileValue.class, fs.getConf().getInt("io.file.buffer.size", 4096),
              replication, fs.getDefaultBlockSize(), SequenceFile.CompressionType.BLOCK, new DefaultCodec(), null, new Metadata());
          FileSystem local = TraceFileSystem.wrap(FileSystem.getLocal(fs.getConf()).getRaw());
          reader = new SequenceFile.Reader(local, new Path(findLocalFilename(localLog)), fs.getConf());
          while (reader.next(key, value)) {
            writer.append(key, value);
          }
        } catch (IOException ex) {
          log.warn("May have a partial copy of a recovery file: " + localLog, ex);
        } finally {
          if (reader != null)
            reader.close();
          if (writer != null)
            writer.close();
        }
        // Make file appear in the shared file system as the target name only after it is completely copied
        fs.rename(dest, new Path(fullyQualifiedFileName));
View Full Code Here

    sorter.merge(outfiles, output);

    // import the descriptions
    Writable key = new LongWritable();
    Writable value = new Text();
    Reader reader = new Reader(fs, output, conf);

    while (reader.next(key, value)) {
      descriptions.add(value.toString());
    }

    reader.close();
  }
View Full Code Here

    sorter.merge(outfiles, output);

    // import the evaluations
    Writable key = new LongWritable();
    CDFitness value = new CDFitness();
    Reader reader = new Reader(fs, output, conf);

    while (reader.next(key, value)) {
      evaluations.add(new CDFitness(value));
    }

    reader.close();
  }
View Full Code Here

    // read all the outputs
    IntWritable key = new IntWritable();
    Step0Output value = new Step0Output(0L, 0);
   
    for (Path path : outfiles) {
      Reader reader = new Reader(fs, path, conf);
     
      try {
        while (reader.next(key, value)) {
          keys.add(key.get());
          values.add(value.clone());
        }
      } finally {
        reader.close();
      }
    }
   
    return processOutput(keys, values);
  }
View Full Code Here

    LongWritable key = new LongWritable();
    Frequencies value = new Frequencies();
   
    int index = 0;
    for (Path path : outfiles) {
      Reader reader = new Reader(fs, path, conf);
     
      try {
        while (reader.next(key, value)) {
          values[index++] = value.clone();
        }
      } finally {
        reader.close();
      }
    }
   
    if (index < numMaps) {
      throw new IllegalStateException("number of output Frequencies (" + index
View Full Code Here

          continue;
        }
        LogFileKey key = new LogFileKey();
        LogFileValue value = new LogFileValue();
        log.info("Openning local log " + file.getPath());
        Reader reader = new SequenceFile.Reader(localfs, file.getPath(), localfs.getConf());
        Path tmp = new Path(Constants.getWalDirectory(conf) + "/" + name + ".copy");
        FSDataOutputStream writer = fs.create(tmp);
        while (reader.next(key, value)) {
          try {
            key.write(writer);
            value.write(writer);
          } catch (EOFException ex) {
            break;
          }
        }
        writer.close();
        reader.close();
        fs.rename(tmp, new Path(tmp.getParent(), name));
        log.info("Copied local log " + name);
        localfs.delete(new Path(localWalDirectory, name), true);
      }
    }
View Full Code Here

      }
      if (dump) {
        if (!fs.isFile(logPath)) {
          throw new IOException(args[i] + " is not a file");
        }
        Reader log = new SequenceFile.Reader(fs, logPath, conf);
        try {
          HLogKey key = new HLogKey();
          HLogEdit val = new HLogEdit();
          while (log.next(key, val)) {
            System.out.println(key.toString() + " " + val.toString());
          }
        } finally {
          log.close();
        }
      } else {
        if (!fs.getFileStatus(logPath).isDir()) {
          throw new IOException(args[i] + " is not a directory");
        }
View Full Code Here

      }
      if (dump) {
        if (!fs.isFile(logPath)) {
          throw new IOException(args[i] + " is not a file");
        }
        Reader log = new SequenceFile.Reader(fs, logPath, conf);
        try {
          HLogKey key = new HLogKey();
          KeyValue val = new KeyValue();
          while (log.next(key, val)) {
            System.out.println(key.toString() + " " + val.toString());
          }
        } finally {
          log.close();
        }
      } else {
        if (!fs.getFileStatus(logPath).isDir()) {
          throw new IOException(args[i] + " is not a directory");
        }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.io.SequenceFile.Reader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.