@@ -618,19 +618,34 @@ impl<'a> std::future::IntoFuture for PreparedCommit<'a> {
618
618
let commit_or_bytes = this. commit_or_bytes ;
619
619
620
620
if this. table_data . is_none ( ) {
621
- this. log_store
621
+ match this
622
+ . log_store
622
623
. write_commit_entry ( 0 , commit_or_bytes. clone ( ) , this. operation_id )
623
- . await ?;
624
- return Ok ( PostCommit {
625
- version : 0 ,
626
- data : this. data ,
627
- create_checkpoint : false ,
628
- cleanup_expired_logs : None ,
629
- log_store : this. log_store ,
630
- table_data : None ,
631
- custom_execute_handler : this. post_commit_hook_handler ,
632
- metrics : CommitMetrics { num_retries : 0 } ,
633
- } ) ;
624
+ . await
625
+ {
626
+ Ok ( _) => {
627
+ return Ok ( PostCommit {
628
+ version : 0 ,
629
+ data : this. data ,
630
+ create_checkpoint : false ,
631
+ cleanup_expired_logs : None ,
632
+ log_store : this. log_store ,
633
+ table_data : None ,
634
+ custom_execute_handler : this. post_commit_hook_handler ,
635
+ metrics : CommitMetrics { num_retries : 0 } ,
636
+ } )
637
+ }
638
+ Err ( TransactionError :: VersionAlreadyExists ( 0 ) ) => {
639
+ // this can happen if the table has been created by another writer since the `this.table_data.is_none()` check above
640
+ // therefore, we need to re-download the table state
641
+ this. table_data = this
642
+ . log_store
643
+ . read_commit_entry ( this. log_store . get_latest_version ( 0 ) . await ?)
644
+ . await ?;
645
+ Ok ( ( ) )
646
+ }
647
+ Err ( e) => Err ( e) ,
648
+ } ?;
634
649
}
635
650
636
651
// unwrap() is safe here due to the above check
0 commit comments