Azure表删除和创建表失败

hpi*_*tyu 4 java azure azure-table-storage

我的问题是我不时想从Java中删除Azure表的内容.该表有数百万行,因此它似乎不是逐个删除所有实体的好方法(因为许多REST API调用).

我试图删除然后再次创建表,但我的代码失败了.

getTableClient().deleteTableIfExists("tablename");
getTableClient().createTableIfNotExists("tablename");
Run Code Online (Sandbox Code Playgroud)

这是我的堆栈跟踪:

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)
Run Code Online (Sandbox Code Playgroud)

我需要在两次通话之间睡一会儿吗?我宁愿不要在这里等待太久,因为我想让这个操作尽可能短,以便其他线程可以在表中再次写入.

或者有一种安全的方法吗?


编辑

是的,我正在寻找一个等效的SQL语句:DELETE FROM tablename;在Azure表中尽可能少的REST API调用.

我目前最好的镜头是:

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) {}
}
Run Code Online (Sandbox Code Playgroud)

我正在寻找一个更好,更安全的解决方案!

mco*_*ier 9

针对Windows Azure表的删除操作不是即时操作.发出删除请求时,存储服务会将其标记为删除,客户端不再可以访问.然后在后台删除该表(垃圾收集).这可能需要几秒钟才能完成.

您将获得409(冲突),因为当代码请求创建具有相同名称的新表时,该表仍然存在.

请参阅MSDN文档的"备注"部分(页面底部),网址http://msdn.microsoft.com/en-us/library/windowsazure/dd179387.aspx.

除了等待(就像你已经完成)或创建一个具有不同名称的表,我不知道另一种选择.

  • 这很有可能发生了什么.实际上,您应该在线路上收到一条错误消息,表明该表正在被删除.您会在异常中的.NET客户端中看到它,不确定为什么您在Java客户端中看不到它.此外,大型表可能需要很多*分钟*(而不是秒)才能进行垃圾回收.在某些情况下,我已经看到超过40分钟的非常大的桌子. (2认同)