Skip to content

Commit

Permalink
avoid streaming empty files with bulk loader if sstablewriter errors out
Browse files Browse the repository at this point in the history
patch by yukim; reviewed by jbellis for CASSANDRA-3946
  • Loading branch information
jbellis committed Apr 17, 2012
1 parent 5434ac4 commit 10a64bd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
@@ -1,4 +1,6 @@
1.0.10
* avoid streaming empty files with bulk loader if sstablewriter errors out
(CASSANDRA-3946)
* support PropertyFileSnitch in bulk loader (CASSANDRA-4145)
* add auto_snapshot option allowing disabling snapshot before drop/truncate
(CASSANDRA-3710)
Expand Down
Expand Up @@ -79,7 +79,7 @@ public boolean accept(File dir, String name)
int maxGen = 0;
for (Descriptor desc : existing)
maxGen = Math.max(maxGen, desc.generation);
return new Descriptor(directory, keyspace, columnFamily, maxGen + 1, false).filenameFor(Component.DATA);
return new Descriptor(directory, keyspace, columnFamily, maxGen + 1, true).filenameFor(Component.DATA);
}

/**
Expand Down
Expand Up @@ -105,12 +105,22 @@ private void sync() throws IOException
if (keys.isEmpty())
return;

SSTableWriter writer = getWriter();
for (Map.Entry<DecoratedKey, ColumnFamily> entry : keys.entrySet())
SSTableWriter writer = null;
try
{
writer.append(entry.getKey(), entry.getValue());
writer = getWriter();
for (Map.Entry<DecoratedKey, ColumnFamily> entry : keys.entrySet())
{
writer.append(entry.getKey(), entry.getValue());
}
writer.closeAndOpenReader();
}
catch (IOException e)
{
if (writer != null)
writer.abort();
throw e;
}
writer.closeAndOpenReader();
currentSize = 0;
keys.clear();
}
Expand Down
14 changes: 11 additions & 3 deletions src/java/org/apache/cassandra/io/sstable/SSTableSimpleWriter.java
Expand Up @@ -67,9 +67,17 @@ public SSTableSimpleWriter(File directory, CFMetaData metadata) throws IOExcepti

public void close() throws IOException
{
if (currentKey != null)
writeRow(currentKey, columnFamily);
writer.closeAndOpenReader();
try
{
if (currentKey != null)
writeRow(currentKey, columnFamily);
writer.closeAndOpenReader();
}
catch (IOException e)
{
writer.abort();
throw e;
}
}

protected void writeRow(DecoratedKey key, ColumnFamily columnFamily) throws IOException
Expand Down

0 comments on commit 10a64bd

Please sign in to comment.