Skip to content

Commit

Permalink
Fix: In some cases a DROP TABLE statment does
Browse files Browse the repository at this point in the history
not delete all
partitions. Now it's possible to repeat the 
statement in order to delete the orphaned
partitions.
  • Loading branch information
Philipp Bogensberger committed May 8, 2015
1 parent 18a8a97 commit bc8d64d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Changes for Crate
Unreleased
==========

- Fix: In some cases a ``DROP TABLE`` statment does not delete all
partitions. Now it's possible to repeat the statement in order
to delete the orphaned partitions.

- Added the IF NOT EXISTS clause to the CREATE TABLE statement

2015/05/07 0.49.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.crate.metadata.PartitionName;
import io.crate.metadata.table.TableInfo;
import io.crate.planner.node.ddl.DropTableNode;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
Expand All @@ -34,6 +35,7 @@
import org.elasticsearch.action.admin.indices.template.delete.TransportDeleteIndexTemplateAction;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.indices.IndexTemplateMissingException;

import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -79,7 +81,13 @@ public void onResponse(DeleteIndexTemplateResponse response) {

@Override
public void onFailure(Throwable e) {
result.setException(e);
e = ExceptionsHelper.unwrapCause(e);
if (e instanceof IndexTemplateMissingException && !tableInfo.partitions().isEmpty()) {
logger.warn(e.getMessage());
deleteESIndex(tableInfo.ident().esName());
} else {
result.setException(e);
}
}
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Matchers;
import org.hamcrest.core.Is;
import org.junit.After;
Expand Down Expand Up @@ -1793,6 +1794,25 @@ public void testFetchPartitionedTable() throws Exception {
assertThat(response.rowCount(), is(lessThanOrEqualTo(1L)));
}


@Test
public void testDeleteOrphanedPartitions() throws Throwable {
execute("create table foo (name string, p string) partitioned by (p) with (number_of_replicas=0, refresh_interval = 0)");
ensureYellow();
execute("insert into foo (name, p) values (?, ?)", new Object[]{"Marvin", 1});
execute("refresh table foo");

String templateName = PartitionName.templateName(null, "foo");
client().admin().indices().prepareDeleteTemplate(templateName).execute().actionGet();
waitNoPendingTasksOnAll();
execute("select * from sys.shards where table_name = 'foo'");
assertThat(response.rowCount(), CoreMatchers.is(5L));
execute("drop table foo");

execute("select * from sys.shards where table_name = 'foo'");
assertThat(response.rowCount(), CoreMatchers.is(0L));
}

@After
@Override
public void tearDown() throws Exception {
Expand Down

0 comments on commit bc8d64d

Please sign in to comment.