<commit_before>package com.neverwinterdp.scribengin.storage.hdfs;

import java.io.IOException;

import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import com.neverwinterdp.util.JSONSerializer;

public class SegmentStorageWriter<T> {
  private SegmentStorage<T> storage;
  private FileSystem        fs;
  private String            location;
  private SegmentWriter     currentBuffer;
  
  public SegmentStorageWriter(SegmentStorage<T> storage) {
    this.storage = storage ;
    this.fs = storage.getFileSystem();
    this.location = storage.getLocation();
  }
  
  public SegmentStorage<T> getStorage() { return this.storage; }
  
  public void append(T obj) throws Exception {
    if(currentBuffer == null) {
      currentBuffer = nextSegmentWriter();
    }
    currentBuffer.append(obj);
  }

  public void prepareCommit() throws Exception {
  }

  public void completeCommit() throws Exception {
    if(currentBuffer == null) return;
    //TODO: reimplement correctly 2 phases commit
    currentBuffer.commit();
    currentBuffer = null ;
  }
  
  synchronized public void commit() throws Exception {
    prepareCommit();
    completeCommit();
  }

  public void rollback() throws Exception {<commit_msg>fix lock fail<commit_after>package com.neverwinterdp.scribengin.storage.hdfs;

import java.io.IOException;

import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import com.neverwinterdp.util.JSONSerializer;

public class SegmentStorageWriter<T> {
  private SegmentStorage<T> storage;
  private FileSystem        fs;
  private String            location;
  private SegmentWriter     currentBuffer;
  
  public SegmentStorageWriter(SegmentStorage<T> storage) {
    this.storage = storage ;
    this.fs = storage.getFileSystem();
    this.location = storage.getLocation();
  }
  
  public SegmentStorage<T> getStorage() { return this.storage; }
  
  public void append(T obj) throws Exception {
    if(currentBuffer == null) {
      currentBuffer = nextSegmentWriter();
    }
    currentBuffer.append(obj);
  }

  public void prepareCommit() throws Exception {
  }

  public void completeCommit() throws Exception {
    if(currentBuffer == null) return;
    //TODO: reimplement correctly 2 phases commit
    currentBuffer.commit();
    currentBuffer = null ;
  }
  
  synchronized public void commit() throws Exception {
    prepareCommit();
    completeCommit();
  }

  public void rollback() throws Exception {
    if(currentBuffer == null) return ;
{'fraction_non_alphanumeric': 0.09510974201001156, 'fraction_numerical': 0.0007701193685021178, 'mean_word_length': 3.7236363636363636, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5330672', 'n_tokens_mistral': 734, 'n_tokens_neox': 739, 'n_words': 179}