-
Notifications
You must be signed in to change notification settings - Fork 40
Implement scanner API for JDBC transactions #2702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,10 +12,12 @@ | |
| import com.scalar.db.api.Result; | ||
| import com.scalar.db.api.Scan; | ||
| import com.scalar.db.api.SerializableStrategy; | ||
| import com.scalar.db.api.TransactionCrudOperable; | ||
| import com.scalar.db.api.TransactionState; | ||
| import com.scalar.db.api.Update; | ||
| import com.scalar.db.api.Upsert; | ||
| import com.scalar.db.common.AbstractDistributedTransactionManager; | ||
| import com.scalar.db.common.AbstractTransactionManagerCrudOperableScanner; | ||
| import com.scalar.db.common.TableMetadataManager; | ||
| import com.scalar.db.common.checker.OperationChecker; | ||
| import com.scalar.db.common.error.CoreError; | ||
|
|
@@ -38,6 +40,7 @@ | |
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import javax.annotation.concurrent.ThreadSafe; | ||
| import org.apache.commons.dbcp2.BasicDataSource; | ||
| import org.slf4j.Logger; | ||
|
|
@@ -170,9 +173,93 @@ public List<Result> scan(Scan scan) throws CrudException, UnknownTransactionStat | |
|
|
||
| @Override | ||
| public Scanner getScanner(Scan scan) throws CrudException { | ||
| throw new UnsupportedOperationException("Implement later"); | ||
| DistributedTransaction transaction; | ||
| try { | ||
| transaction = begin(); | ||
| } catch (TransactionNotFoundException e) { | ||
| throw new CrudConflictException(e.getMessage(), e, e.getTransactionId().orElse(null)); | ||
| } catch (TransactionException e) { | ||
| throw new CrudException(e.getMessage(), e, e.getTransactionId().orElse(null)); | ||
| } | ||
|
|
||
| TransactionCrudOperable.Scanner scanner; | ||
| try { | ||
| scanner = transaction.getScanner(copyAndSetTargetToIfNot(scan)); | ||
| } catch (CrudException e) { | ||
| rollbackTransaction(transaction); | ||
| throw e; | ||
| } | ||
|
|
||
| return new AbstractTransactionManagerCrudOperableScanner() { | ||
|
|
||
| private final AtomicBoolean closed = new AtomicBoolean(); | ||
|
|
||
| @Override | ||
| public Optional<Result> one() throws CrudException { | ||
| try { | ||
| return scanner.one(); | ||
| } catch (CrudException e) { | ||
| closed.set(true); | ||
|
|
||
| try { | ||
| scanner.close(); | ||
| } catch (CrudException ex) { | ||
| e.addSuppressed(ex); | ||
| } | ||
|
|
||
| rollbackTransaction(transaction); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public List<Result> all() throws CrudException { | ||
| try { | ||
| return scanner.all(); | ||
| } catch (CrudException e) { | ||
| closed.set(true); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [minor] How about moving this after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If Do you still think it’s necessary to move There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only thought in the current implementation there is no way to re-try to close |
||
|
|
||
| try { | ||
| scanner.close(); | ||
| } catch (CrudException ex) { | ||
| e.addSuppressed(ex); | ||
| } | ||
|
|
||
| rollbackTransaction(transaction); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void close() throws CrudException, UnknownTransactionStatusException { | ||
| if (closed.get()) { | ||
| return; | ||
| } | ||
| closed.set(true); | ||
|
|
||
| try { | ||
| scanner.close(); | ||
| } catch (CrudException e) { | ||
| rollbackTransaction(transaction); | ||
| throw e; | ||
| } | ||
|
|
||
| try { | ||
| transaction.commit(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If CrudException is thrown from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If CrudException is thrown from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. Sounds good! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I confused this with |
||
| } catch (CommitConflictException e) { | ||
| rollbackTransaction(transaction); | ||
| throw new CrudConflictException(e.getMessage(), e, e.getTransactionId().orElse(null)); | ||
| } catch (UnknownTransactionStatusException e) { | ||
| throw e; | ||
| } catch (TransactionException e) { | ||
| rollbackTransaction(transaction); | ||
| throw new CrudException(e.getMessage(), e, e.getTransactionId().orElse(null)); | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** @deprecated As of release 3.13.0. Will be removed in release 5.0.0. */ | ||
| @Deprecated | ||
| @Override | ||
| public void put(Put put) throws CrudException, UnknownTransactionStatusException { | ||
|
|
@@ -183,6 +270,7 @@ public void put(Put put) throws CrudException, UnknownTransactionStatusException | |
| }); | ||
| } | ||
|
|
||
| /** @deprecated As of release 3.13.0. Will be removed in release 5.0.0. */ | ||
| @Deprecated | ||
| @Override | ||
| public void put(List<Put> puts) throws CrudException, UnknownTransactionStatusException { | ||
|
|
@@ -229,6 +317,7 @@ public void delete(Delete delete) throws CrudException, UnknownTransactionStatus | |
| }); | ||
| } | ||
|
|
||
| /** @deprecated As of release 3.13.0. Will be removed in release 5.0.0. */ | ||
| @Deprecated | ||
| @Override | ||
| public void delete(List<Delete> deletes) throws CrudException, UnknownTransactionStatusException { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.