Configure a timeout based on the options set for this transaction. This timeout only applies if we don't have an underlying database object to connect with.
| 1497 | // Configure a timeout based on the options set for this transaction. This timeout only applies |
| 1498 | // if we don't have an underlying database object to connect with. |
| 1499 | void MultiVersionTransaction::setTimeout(Optional<StringRef> value) { |
| 1500 | double timeoutDuration = extractIntOption(value, 0, std::numeric_limits<int>::max()) / 1000.0; |
| 1501 | |
| 1502 | ThreadFuture<Void> prevTimeout; |
| 1503 | double transactionStartTime = startTime; |
| 1504 | |
| 1505 | { // lock scope |
| 1506 | ThreadSpinLockHolder holder(timeoutLock); |
| 1507 | prevTimeout = currentTimeout; |
| 1508 | |
| 1509 | if (timeoutDuration > 0) { |
| 1510 | Reference<ThreadSingleAssignmentVar<Void>> tsav = timeoutTsav; |
| 1511 | ThreadFuture<Void> newTimeout = onMainThread([transactionStartTime, tsav, timeoutDuration]() { |
| 1512 | return timeoutImpl(tsav, timeoutDuration - std::max(0.0, now() - transactionStartTime)); |
| 1513 | }); |
| 1514 | currentTimeout = newTimeout; |
| 1515 | } else { |
| 1516 | currentTimeout = ThreadFuture<Void>(); |
| 1517 | } |
| 1518 | } |
| 1519 | |
| 1520 | // Cancel the previous timeout now that we have a new one. This means that changing the timeout |
| 1521 | // affects in-flight operations, which is consistent with the behavior in RYW. |
| 1522 | if (prevTimeout.isValid()) { |
| 1523 | prevTimeout.cancel(); |
| 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | // Creates a ThreadFuture<T> that will signal an error if the transaction times out. |
| 1528 | template <class T> |