我的問題是,我不時想刪除來自Java的Azure表的內容。該表擁有數百萬行,因此它似乎不是逐個刪除所有實體的好方法(因爲有很多REST API調用)。Azure Tables刪除並創建表失敗
我試圖刪除,然後再次創建表,但我的代碼失敗。
getTableClient().deleteTableIfExists("tablename");
getTableClient().createTableIfNotExists("tablename");
這裏是我的堆棧跟蹤:
com.microsoft.windowsazure.services.table.client.TableServiceException: Conflict
at com.microsoft.windowsazure.services.table.client.TableServiceException.generateTableServiceException(TableServiceException.java:57)
at com.microsoft.windowsazure.services.table.client.TableOperation$2.execute(TableOperation.java:339)
at com.microsoft.windowsazure.services.table.client.TableOperation$2.execute(TableOperation.java:322)
at com.microsoft.windowsazure.services.core.storage.utils.implementation.ExecutionEngine.executeWithRetry(ExecutionEngine.java:110)
at com.microsoft.windowsazure.services.table.client.TableOperation.performInsert(TableOperation.java:374)
at com.microsoft.windowsazure.services.table.client.TableOperation.execute(TableOperation.java:551)
at com.microsoft.windowsazure.services.table.client.CloudTableClient.execute(CloudTableClient.java:638)
at com.microsoft.windowsazure.services.table.client.CloudTableClient.createTable(CloudTableClient.java:173)
at com.microsoft.windowsazure.services.table.client.CloudTableClient.createTableIfNotExists(CloudTableClient.java:251)
at com.microsoft.windowsazure.services.table.client.CloudTableClient.createTableIfNotExists(CloudTableClient.java:197)
我必須一會兒之間睡覺兩個電話?我寧願在這裏等待,因爲我希望儘可能縮短這個操作的時間,以便其他線程可以在表中再次寫入。
還是有安全的方法來做到這一點?在Azure中的表使用盡可能少的REST API調用盡可能DELETE FROM tablename;
:
編輯
是的,我正在尋找的SQL語句的等效。
我目前最好的拍攝是:
getTableClient().deleteTableIfExists("tablename");
// TODO: solve problem with new creation!
boolean success = false;
while (!success) {
try {
success = getTableClient().createTableIfNotExists("tablename");
} catch (StorageException e) {
System.err.println("Log table recreation failed retrying in 5 sec");
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {}
}
我找一個更好,更安全的解決方案,然後這個!
不,你正在尋找SQL Drop Table。您不希望被實體(行)刪除,因爲這可能是多個(結算)事務。刪除表是一個事務。 – Paparazzi