mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-24 16:20:15 +08:00
Merge pull request #1725 from jzhou77/db-option
Add transaction size option
This commit is contained in:
commit
e8c75505d3
bindings
flow/tester
go/src/fdb
python/tests
ruby/tests
documentation/sphinx/source
fdbclient
DatabaseBackupAgent.actor.cppDatabaseContext.hKnobs.hNativeAPI.actor.cppNativeAPI.actor.hReadYourWrites.h
vexillographer
fdbserver
@ -1550,6 +1550,7 @@ struct UnitTestsFunc : InstructionFunc {
|
||||
const uint64_t retryLimit = 50;
|
||||
const uint64_t noRetryLimit = -1;
|
||||
const uint64_t maxRetryDelay = 100;
|
||||
const uint64_t sizeLimit = 100000;
|
||||
|
||||
data->db->setDatabaseOption(FDBDatabaseOption::FDB_DB_OPTION_LOCATION_CACHE_SIZE, Optional<StringRef>(StringRef((const uint8_t*)&locationCacheSize, 8)));
|
||||
data->db->setDatabaseOption(FDBDatabaseOption::FDB_DB_OPTION_MAX_WATCHES, Optional<StringRef>(StringRef((const uint8_t*)&maxWatches, 8)));
|
||||
@ -1558,6 +1559,7 @@ struct UnitTestsFunc : InstructionFunc {
|
||||
data->db->setDatabaseOption(FDBDatabaseOption::FDB_DB_OPTION_TRANSACTION_TIMEOUT, Optional<StringRef>(StringRef((const uint8_t*)&timeout, 8)));
|
||||
data->db->setDatabaseOption(FDBDatabaseOption::FDB_DB_OPTION_TRANSACTION_TIMEOUT, Optional<StringRef>(StringRef((const uint8_t*)&noTimeout, 8)));
|
||||
data->db->setDatabaseOption(FDBDatabaseOption::FDB_DB_OPTION_TRANSACTION_MAX_RETRY_DELAY, Optional<StringRef>(StringRef((const uint8_t*)&maxRetryDelay, 8)));
|
||||
data->db->setDatabaseOption(FDBDatabaseOption::FDB_DB_OPTION_TRANSACTION_SIZE_LIMIT, Optional<StringRef>(StringRef((const uint8_t*)&sizeLimit, 8)));
|
||||
data->db->setDatabaseOption(FDBDatabaseOption::FDB_DB_OPTION_TRANSACTION_RETRY_LIMIT, Optional<StringRef>(StringRef((const uint8_t*)&retryLimit, 8)));
|
||||
data->db->setDatabaseOption(FDBDatabaseOption::FDB_DB_OPTION_TRANSACTION_RETRY_LIMIT, Optional<StringRef>(StringRef((const uint8_t*)&noRetryLimit, 8)));
|
||||
data->db->setDatabaseOption(FDBDatabaseOption::FDB_DB_OPTION_SNAPSHOT_RYW_ENABLE);
|
||||
|
@ -277,6 +277,13 @@ func (o DatabaseOptions) SetTransactionMaxRetryDelay(param int64) error {
|
||||
return o.setOpt(502, int64ToBytes(param))
|
||||
}
|
||||
|
||||
// Set the maximum transaction size which, if exceeded, will cause the transaction to be cancelled. Default to 10,000,000 bytes.
|
||||
//
|
||||
// Parameter: value in bytes
|
||||
func (o DatabaseOptions) SetTransactionSizeLimit(param int64) error {
|
||||
return o.setOpt(503, int64ToBytes(param))
|
||||
}
|
||||
|
||||
// Snapshot read operations will see the results of writes done in the same transaction. This is the default behavior.
|
||||
func (o DatabaseOptions) SetSnapshotRywEnable() error {
|
||||
return o.setOpt(26, nil)
|
||||
@ -402,6 +409,13 @@ func (o TransactionOptions) SetMaxRetryDelay(param int64) error {
|
||||
return o.setOpt(502, int64ToBytes(param))
|
||||
}
|
||||
|
||||
// Set the maximum transaction size which, if exceeded, will cause the transaction to be cancelled. Valid parameter values are ``[32, 10,000,000]```.
|
||||
//
|
||||
// Parameter: value in bytes
|
||||
func (o TransactionOptions) SetSizeLimit(param int64) error {
|
||||
return o.setOpt(503, int64ToBytes(param))
|
||||
}
|
||||
|
||||
// Snapshot read operations will see the results of writes done in the same transaction. This is the default behavior.
|
||||
func (o TransactionOptions) SetSnapshotRywEnable() error {
|
||||
return o.setOpt(600, nil)
|
||||
@ -451,7 +465,7 @@ const (
|
||||
// Infrequently used. The client has passed a specific row limit and wants
|
||||
// that many rows delivered in a single batch. Because of iterator operation
|
||||
// in client drivers make request batches transparent to the user, consider
|
||||
// “WANT_ALL“ StreamingMode instead. A row limit must be specified if this
|
||||
// ``WANT_ALL`` StreamingMode instead. A row limit must be specified if this
|
||||
// mode is used.
|
||||
StreamingModeExact StreamingMode = 1
|
||||
|
||||
@ -568,15 +582,15 @@ type ErrorPredicate int
|
||||
|
||||
const (
|
||||
|
||||
// Returns “true“ if the error indicates the operations in the transactions
|
||||
// should be retried because of transient error.
|
||||
// Returns ``true`` if the error indicates the operations in the
|
||||
// transactions should be retried because of transient error.
|
||||
ErrorPredicateRetryable ErrorPredicate = 50000
|
||||
|
||||
// Returns “true“ if the error indicates the transaction may have succeeded,
|
||||
// though not in a way the system can verify.
|
||||
// Returns ``true`` if the error indicates the transaction may have
|
||||
// succeeded, though not in a way the system can verify.
|
||||
ErrorPredicateMaybeCommitted ErrorPredicate = 50001
|
||||
|
||||
// Returns “true“ if the error indicates the transaction has not committed,
|
||||
// though in a way that can be retried.
|
||||
// Returns ``true`` if the error indicates the transaction has not
|
||||
// committed, though in a way that can be retried.
|
||||
ErrorPredicateRetryableNotCommitted ErrorPredicate = 50002
|
||||
)
|
||||
|
64
bindings/python/tests/size_limit.py
Normal file
64
bindings/python/tests/size_limit.py
Normal file
@ -0,0 +1,64 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# size_limit.py
|
||||
#
|
||||
# This source file is part of the FoundationDB open source project
|
||||
#
|
||||
# Copyright 2013-2019 Apple Inc. and the FoundationDB project authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
import fdb
|
||||
import sys
|
||||
|
||||
fdb.api_version(610)
|
||||
|
||||
@fdb.transactional
|
||||
def setValue(tr, key, value):
|
||||
tr[key] = value
|
||||
|
||||
@fdb.transactional
|
||||
def setValueWithLimit(tr, key, value, limit):
|
||||
tr.options.set_size_limit(limit)
|
||||
tr[key] = value
|
||||
|
||||
def run(clusterFile):
|
||||
db = fdb.open(clusterFile)
|
||||
db.options.set_transaction_timeout(2000) # 2 seconds
|
||||
db.options.set_transaction_retry_limit(3)
|
||||
value = 'a' * 1024
|
||||
|
||||
setValue(db, 't1', value)
|
||||
assert(value == db['t1'])
|
||||
|
||||
try:
|
||||
db.options.set_transaction_size_limit(1000)
|
||||
setValue(db, 't2', value)
|
||||
assert(False) # not reached
|
||||
except fdb.impl.FDBError as e:
|
||||
assert(e.code == 2101) # Transaction exceeds byte limit (2101)
|
||||
|
||||
# Per transaction option overrides database option
|
||||
db.options.set_transaction_size_limit(1000000)
|
||||
try:
|
||||
setValueWithLimit(db, 't3', value, 1000)
|
||||
assert(False) # not reached
|
||||
except fdb.impl.FDBError as e:
|
||||
assert(e.code == 2101) # Transaction exceeds byte limit (2101)
|
||||
|
||||
|
||||
# Expect a cluster file as input. This test will write to the FDB cluster, so
|
||||
# be aware of potential side effects.
|
||||
if __name__ == '__main__':
|
||||
clusterFile = sys.argv[1]
|
||||
run(clusterFile)
|
@ -133,6 +133,7 @@ def test_db_options(db):
|
||||
db.options.set_transaction_timeout(0)
|
||||
db.options.set_transaction_timeout(0)
|
||||
db.options.set_transaction_max_retry_delay(100)
|
||||
db.options.set_transaction_size_limit(100000)
|
||||
db.options.set_transaction_retry_limit(10)
|
||||
db.options.set_transaction_retry_limit(-1)
|
||||
db.options.set_snapshot_ryw_enable()
|
||||
|
@ -459,6 +459,7 @@ class Tester
|
||||
@db.options.set_transaction_timeout(100000)
|
||||
@db.options.set_transaction_timeout(0)
|
||||
@db.options.set_transaction_max_retry_delay(100)
|
||||
@db.options.set_transaction_size_limit(100000)
|
||||
@db.options.set_transaction_retry_limit(10)
|
||||
@db.options.set_transaction_retry_limit(-1)
|
||||
@db.options.set_snapshot_ryw_enable()
|
||||
|
@ -40,12 +40,14 @@
|
||||
.. |retry-limit-transaction-option| replace:: FIXME
|
||||
.. |timeout-transaction-option| replace:: FIXME
|
||||
.. |max-retry-delay-transaction-option| replace:: FIXME
|
||||
.. |size-limit-transaction-option| replace:: FIXME
|
||||
.. |snapshot-ryw-enable-transaction-option| replace:: FIXME
|
||||
.. |snapshot-ryw-disable-transaction-option| replace:: FIXME
|
||||
.. |snapshot-ryw-enable-database-option| replace:: FIXME
|
||||
.. |snapshot-ryw-disable-database-option| replace:: FIXME
|
||||
.. |retry-limit-database-option| replace:: FIXME
|
||||
.. |max-retry-delay-database-option| replace:: FIXME
|
||||
.. |transaction-size-limit-database-option| replace:: FIXME
|
||||
.. |timeout-database-option| replace:: FIXME
|
||||
|
||||
.. include:: api-common.rst.inc
|
||||
|
@ -306,6 +306,10 @@
|
||||
|
||||
Set the default maximum number of retries for each transaction after which additional calls to |on-error-func| will throw the most recently seen error code. This is equivalent to calling |retry-limit-transaction-option| on each transaction created by this database.
|
||||
|
||||
.. |option-db-tr-size-limit-blurb| replace::
|
||||
|
||||
Set the default maximum transaction size in bytes. This is equivalent to calling |transaction-size-limit-database-option| on each transaction created by this database.
|
||||
|
||||
.. |option-db-tr-timeout-blurb| replace::
|
||||
|
||||
Set the default timeout duration in milliseconds after which all transactions created by this database will automatically be cancelled. This is equivalent to calling |timeout-transaction-option| on each transaction created by this database. This option can only be called if the API version is at least 610.
|
||||
@ -393,6 +397,10 @@
|
||||
|
||||
Set the maximum backoff delay incurred in the call to |on-error-func| if the error is retryable. Prior to API version 610, like all other transaction options, the maximum retry delay must be reset after a call to |on-error-func|. If the API version is 610 or newer, then the maximum retry delay is not reset. Note that at all API versions, it is safe and legal to call this option after each call to |on-error-func|, so most cade written assuming the older behavior can be upgraded without requiring any modification. This also means there is no need to introduce logic to conditionally set this option within retry loops. One can set the default retry limit for all transactions by calling |max-retry-delay-database-option|.
|
||||
|
||||
.. |option-set-size-limit-blurb| replace::
|
||||
|
||||
Set the maximum transaction size limit in bytes. The size is calculated by combining the sizes of all keys and values written or mutated, all key ranges cleared, and all read and write conflict ranges. (In other words, it includes the total size of all data included in the request to the cluster to commit the transaction.) Large transactions can cause performance problems on FoundationDB clusters, so setting this limit to a smaller value than the default can help prevent the client from accidentally degrading the cluster's performance. This value must be at least 32 and cannot be set to higher than 10,000,000, the default transaction size limit. The value set by this limit will persist across transaction resets.
|
||||
|
||||
.. |option-set-timeout-blurb1| replace::
|
||||
|
||||
Set a timeout duration in milliseconds after which the transaction automatically to be cancelled. The time is measured from transaction creation (or the most call to |reset-func-name|, if any). Valid parameter values are [0, INT_MAX]. If set to 0, all timeouts will be disabled. Once a transaction has timed out, all pending or future uses of the transaction will |error-raise-type| a :ref:`transaction_timed_out <developer-guide-error-codes>` |error-type|. The transaction can be used again after it is |reset-func-name|.
|
||||
|
@ -24,6 +24,7 @@
|
||||
.. |retry-limit-database-option| replace:: :func:`Database.options.set_transaction_retry_limit`
|
||||
.. |timeout-database-option| replace:: :func:`Database.options.set_transaction_timeout`
|
||||
.. |max-retry-delay-database-option| replace:: :func:`Database.options.set_transaction_max_retry_delay`
|
||||
.. |transaction-size-limit-database-option| replace:: :func:`Database.options.set_transaction_size_limit`
|
||||
.. |snapshot-ryw-enable-database-option| replace:: :func:`Database.options.set_snapshot_ryw_enable`
|
||||
.. |snapshot-ryw-disable-database-option| replace:: :func:`Database.options.set_snapshot_ryw_disable`
|
||||
.. |future-type-string| replace:: a :ref:`future <api-python-future>`
|
||||
@ -31,6 +32,7 @@
|
||||
.. |retry-limit-transaction-option| replace:: :func:`Transaction.options.set_retry_limit`
|
||||
.. |timeout-transaction-option| replace:: :func:`Transaction.options.set_timeout`
|
||||
.. |max-retry-delay-transaction-option| replace:: :func:`Transaction.options.set_max_retry_delay`
|
||||
.. |size-limit-transaction-option| replace:: :func:`Transaction.options.set_size_limit`
|
||||
.. |snapshot-ryw-enable-transaction-option| replace:: :func:`Transaction.options.set_snapshot_ryw_enable`
|
||||
.. |snapshot-ryw-disable-transaction-option| replace:: :func:`Transaction.options.set_snapshot_ryw_disable`
|
||||
.. |lazy-iterator-object| replace:: generator
|
||||
@ -378,6 +380,10 @@ Database options
|
||||
|
||||
|option-db-tr-max-retry-delay-blurb|
|
||||
|
||||
.. method:: Database.options.set_transaction_size_limit(size_limit)
|
||||
|
||||
|option-db-tr-size-limit-blurb|
|
||||
|
||||
.. method:: Database.options.set_snapshot_ryw_enable()
|
||||
|
||||
|option-db-snapshot-ryw-enable-blurb|
|
||||
@ -835,6 +841,10 @@ Transaction options
|
||||
|
||||
|option-set-max-retry-delay-blurb|
|
||||
|
||||
.. method:: Transaction.options.set_size_limit
|
||||
|
||||
|option-set-size-limit-blurb|
|
||||
|
||||
.. _api-python-timeout:
|
||||
|
||||
.. method:: Transaction.options.set_timeout
|
||||
|
@ -22,6 +22,7 @@
|
||||
.. |retry-limit-database-option| replace:: :meth:`Database.options.set_transaction_retry_limit`
|
||||
.. |timeout-database-option| replace:: :meth:`Database.options.set_transaction_timeout`
|
||||
.. |max-retry-delay-database-option| replace:: :meth:`Database.options.set_transaction_max_retry_delay`
|
||||
.. |transaction-size-limit-database-option| replace:: :func:`Database.options.set_transaction_size_limit`
|
||||
.. |snapshot-ryw-enable-database-option| replace:: :meth:`Database.options.set_snapshot_ryw_enable`
|
||||
.. |snapshot-ryw-disable-database-option| replace:: :meth:`Database.options.set_snapshot_ryw_disable`
|
||||
.. |future-type-string| replace:: a :class:`Future`
|
||||
@ -29,6 +30,7 @@
|
||||
.. |retry-limit-transaction-option| replace:: :meth:`Transaction.options.set_retry_limit`
|
||||
.. |timeout-transaction-option| replace:: :meth:`Transaction.options.set_timeout`
|
||||
.. |max-retry-delay-transaction-option| replace:: :meth:`Transaction.options.set_max_retry_delay`
|
||||
.. |size-limit-transaction-option| replace:: :meth:`Transaction.options.set_size_limit`
|
||||
.. |snapshot-ryw-enable-transaction-option| replace:: :meth:`Transaction.options.set_snapshot_ryw_enable`
|
||||
.. |snapshot-ryw-disable-transaction-option| replace:: :meth:`Transaction.options.set_snapshot_ryw_disable`
|
||||
.. |lazy-iterator-object| replace:: :class:`Enumerator`
|
||||
@ -374,6 +376,10 @@ Database options
|
||||
|
||||
|option-db-tr-max-retry-delay-blurb|
|
||||
|
||||
.. method:: Database.options.set_transaction_size_limit(size_limit) -> nil
|
||||
|
||||
|option-db-tr-size-limit-blurb|
|
||||
|
||||
.. method:: Database.options.set_snapshot_ryw_enable() -> nil
|
||||
|
||||
|option-db-snapshot-ryw-enable-blurb|
|
||||
@ -779,6 +785,10 @@ Transaction options
|
||||
|
||||
|option-set-max-retry-delay-blurb|
|
||||
|
||||
.. method:: Transaction.options.set_size_limit() -> nil
|
||||
|
||||
|option-set-size-limit-blurb|
|
||||
|
||||
.. method:: Transaction.options.set_timeout() -> nil
|
||||
|
||||
|option-set-timeout-blurb1|
|
||||
|
@ -42,12 +42,14 @@
|
||||
.. |retry-limit-transaction-option| replace:: FIXME
|
||||
.. |timeout-transaction-option| replace:: FIXME
|
||||
.. |max-retry-delay-transaction-option| replace:: FIXME
|
||||
.. |size-limit-transaction-option| replace:: FIXME
|
||||
.. |snapshot-ryw-enable-transaction-option| replace:: FIXME
|
||||
.. |snapshot-ryw-disable-transaction-option| replace:: FIXME
|
||||
.. |snapshot-ryw-enable-database-option| replace:: FIXME
|
||||
.. |snapshot-ryw-disable-database-option| replace:: FIXME
|
||||
.. |retry-limit-database-option| replace:: FIXME
|
||||
.. |max-retry-delay-database-option| replace:: FIXME
|
||||
.. |transaction-size-limit-database-option| replace:: FIXME
|
||||
.. |timeout-database-option| replace:: FIXME
|
||||
|
||||
.. include:: api-common.rst.inc
|
||||
|
@ -42,12 +42,14 @@
|
||||
.. |retry-limit-transaction-option| replace:: FIXME
|
||||
.. |timeout-transaction-option| replace:: FIXME
|
||||
.. |max-retry-delay-transaction-option| replace:: FIXME
|
||||
.. |size-limit-transaction-option| replace:: FIXME
|
||||
.. |snapshot-ryw-enable-transaction-option| replace:: FIXME
|
||||
.. |snapshot-ryw-disable-transaction-option| replace:: FIXME
|
||||
.. |snapshot-ryw-enable-database-option| replace:: FIXME
|
||||
.. |snapshot-ryw-disable-database-option| replace:: FIXME
|
||||
.. |retry-limit-database-option| replace:: FIXME
|
||||
.. |max-retry-delay-database-option| replace:: FIXME
|
||||
.. |transaction-size-limit-database-option| replace:: FIXME
|
||||
.. |timeout-database-option| replace:: FIXME
|
||||
|
||||
.. include:: api-common.rst.inc
|
||||
|
@ -584,7 +584,7 @@ namespace dbBackup {
|
||||
loop{
|
||||
try {
|
||||
tr.setOption(FDBTransactionOptions::LOCK_AWARE);
|
||||
tr.options.customTransactionSizeLimit = 2 * CLIENT_KNOBS->TRANSACTION_SIZE_LIMIT;
|
||||
tr.options.sizeLimit = 2 * CLIENT_KNOBS->TRANSACTION_SIZE_LIMIT;
|
||||
wait(checkDatabaseLock(&tr, BinaryReader::fromStringRef<UID>(task->params[BackupAgentBase::keyConfigLogUid], Unversioned())));
|
||||
state int64_t bytesSet = 0;
|
||||
|
||||
@ -1080,7 +1080,7 @@ namespace dbBackup {
|
||||
loop{
|
||||
try {
|
||||
tr.setOption(FDBTransactionOptions::LOCK_AWARE);
|
||||
tr.options.customTransactionSizeLimit = 2 * CLIENT_KNOBS->TRANSACTION_SIZE_LIMIT;
|
||||
tr.options.sizeLimit = 2 * CLIENT_KNOBS->TRANSACTION_SIZE_LIMIT;
|
||||
wait(checkDatabaseLock(&tr, BinaryReader::fromStringRef<UID>(task->params[BackupAgentBase::keyConfigLogUid], Unversioned())));
|
||||
state int64_t bytesSet = 0;
|
||||
|
||||
|
@ -157,6 +157,7 @@ public:
|
||||
double transactionTimeout;
|
||||
int transactionMaxRetries;
|
||||
double transactionMaxBackoff;
|
||||
int transactionMaxSize; // Max size in bytes.
|
||||
int snapshotRywEnabled;
|
||||
|
||||
Future<Void> logger;
|
||||
|
@ -51,7 +51,7 @@ public:
|
||||
double RESOURCE_CONSTRAINED_MAX_BACKOFF;
|
||||
int PROXY_COMMIT_OVERHEAD_BYTES;
|
||||
|
||||
int64_t TRANSACTION_SIZE_LIMIT;
|
||||
int TRANSACTION_SIZE_LIMIT;
|
||||
int64_t KEY_SIZE_LIMIT;
|
||||
int64_t SYSTEM_KEY_SIZE_LIMIT;
|
||||
int64_t VALUE_SIZE_LIMIT;
|
||||
|
@ -18,33 +18,36 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "fdbclient/DatabaseContext.h"
|
||||
#include "fdbclient/NativeAPI.actor.h"
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#include "fdbclient/Atomic.h"
|
||||
#include "flow/Platform.h"
|
||||
#include "flow/ActorCollection.h"
|
||||
#include "fdbclient/ClusterInterface.h"
|
||||
#include "fdbclient/CoordinationInterface.h"
|
||||
#include "fdbclient/DatabaseContext.h"
|
||||
#include "fdbclient/FailureMonitorClient.h"
|
||||
#include "fdbclient/KeyRangeMap.h"
|
||||
#include "fdbclient/Knobs.h"
|
||||
#include "fdbclient/MasterProxyInterface.h"
|
||||
#include "fdbclient/MonitorLeader.h"
|
||||
#include "fdbclient/MutationList.h"
|
||||
#include "fdbclient/StorageServerInterface.h"
|
||||
#include "fdbclient/SystemData.h"
|
||||
#include "fdbrpc/LoadBalance.h"
|
||||
#include "fdbclient/StorageServerInterface.h"
|
||||
#include "fdbclient/MasterProxyInterface.h"
|
||||
#include "fdbclient/ClusterInterface.h"
|
||||
#include "fdbclient/FailureMonitorClient.h"
|
||||
#include "fdbrpc/Net2FileSystem.h"
|
||||
#include "fdbrpc/simulator.h"
|
||||
#include "fdbrpc/TLSConnection.h"
|
||||
#include "flow/ActorCollection.h"
|
||||
#include "flow/DeterministicRandom.h"
|
||||
#include "fdbclient/KeyRangeMap.h"
|
||||
#include "flow/Knobs.h"
|
||||
#include "flow/Platform.h"
|
||||
#include "flow/SystemMonitor.h"
|
||||
#include "fdbclient/MutationList.h"
|
||||
#include "fdbclient/CoordinationInterface.h"
|
||||
#include "fdbclient/MonitorLeader.h"
|
||||
#include "flow/UnitTest.h"
|
||||
|
||||
#if defined(CMAKE_BUILD) || !defined(WIN32)
|
||||
#include "versions.h"
|
||||
#endif
|
||||
#include "fdbrpc/TLSConnection.h"
|
||||
#include "flow/Knobs.h"
|
||||
#include "fdbclient/Knobs.h"
|
||||
#include "fdbrpc/Net2FileSystem.h"
|
||||
#include "fdbrpc/simulator.h"
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#ifdef WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
@ -58,7 +61,6 @@
|
||||
|
||||
extern const char* getHGVersion();
|
||||
|
||||
using std::make_pair;
|
||||
using std::max;
|
||||
using std::min;
|
||||
using std::pair;
|
||||
@ -522,6 +524,7 @@ DatabaseContext::DatabaseContext(
|
||||
maxOutstandingWatches = CLIENT_KNOBS->DEFAULT_MAX_OUTSTANDING_WATCHES;
|
||||
|
||||
transactionMaxBackoff = CLIENT_KNOBS->FAILURE_MAX_DELAY;
|
||||
transactionMaxSize = CLIENT_KNOBS->TRANSACTION_SIZE_LIMIT;
|
||||
snapshotRywEnabled = apiVersionAtLeast(300) ? 1 : 0;
|
||||
|
||||
logger = databaseLogger( this );
|
||||
@ -668,12 +671,10 @@ bool DatabaseContext::getCachedLocations( const KeyRangeRef& range, vector<std::
|
||||
result.clear();
|
||||
return false;
|
||||
}
|
||||
result.push_back( make_pair(r->range() & range, r->value()) );
|
||||
if(result.size() == limit)
|
||||
break;
|
||||
|
||||
if(begin == end)
|
||||
result.emplace_back(r->range() & range, r->value());
|
||||
if (result.size() == limit || begin == end) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(reverse)
|
||||
--end;
|
||||
@ -778,6 +779,10 @@ void DatabaseContext::setOption( FDBDatabaseOptions::Option option, Optional<Str
|
||||
validateOptionValue(value, true);
|
||||
transactionMaxBackoff = extractIntOption(value, 0, std::numeric_limits<int32_t>::max()) / 1000.0;
|
||||
break;
|
||||
case FDBDatabaseOptions::TRANSACTION_SIZE_LIMIT:
|
||||
validateOptionValue(value, true);
|
||||
transactionMaxSize = extractIntOption(value, 32, CLIENT_KNOBS->TRANSACTION_SIZE_LIMIT);
|
||||
break;
|
||||
case FDBDatabaseOptions::SNAPSHOT_RYW_ENABLE:
|
||||
validateOptionValue(value, false);
|
||||
snapshotRywEnabled++;
|
||||
@ -1282,7 +1287,7 @@ ACTOR Future< vector< pair<KeyRange,Reference<LocationInfo>> > > getKeyRangeLoca
|
||||
state int shard = 0;
|
||||
for (; shard < rep.results.size(); shard++) {
|
||||
//FIXME: these shards are being inserted into the map sequentially, it would be much more CPU efficient to save the map pairs and insert them all at once.
|
||||
results.push_back( make_pair(rep.results[shard].first & keys, cx->setCachedLocation(rep.results[shard].first, rep.results[shard].second)) );
|
||||
results.emplace_back(rep.results[shard].first & keys, cx->setCachedLocation(rep.results[shard].first, rep.results[shard].second));
|
||||
wait(yield());
|
||||
}
|
||||
|
||||
@ -2454,6 +2459,7 @@ double Transaction::getBackoff(int errCode) {
|
||||
|
||||
TransactionOptions::TransactionOptions(Database const& cx) {
|
||||
maxBackoff = cx->transactionMaxBackoff;
|
||||
sizeLimit = cx->transactionMaxSize;
|
||||
reset(cx);
|
||||
if (BUGGIFY) {
|
||||
commitOnFirstProxy = true;
|
||||
@ -2467,13 +2473,16 @@ TransactionOptions::TransactionOptions(Database const& cx) {
|
||||
TransactionOptions::TransactionOptions() {
|
||||
memset(this, 0, sizeof(*this));
|
||||
maxBackoff = CLIENT_KNOBS->DEFAULT_MAX_BACKOFF;
|
||||
sizeLimit = CLIENT_KNOBS->TRANSACTION_SIZE_LIMIT;
|
||||
}
|
||||
|
||||
void TransactionOptions::reset(Database const& cx) {
|
||||
double oldMaxBackoff = maxBackoff;
|
||||
double oldMaxRetries = maxRetries;
|
||||
uint32_t oldSizeLimit = sizeLimit;
|
||||
memset(this, 0, sizeof(*this));
|
||||
maxBackoff = cx->apiVersionAtLeast(610) ? oldMaxBackoff : cx->transactionMaxBackoff;
|
||||
sizeLimit = oldSizeLimit;
|
||||
maxRetries = oldMaxRetries;
|
||||
lockAware = cx->lockAware;
|
||||
}
|
||||
@ -2820,8 +2829,9 @@ Future<Void> Transaction::commitMutations() {
|
||||
transactionSize = tr.transaction.mutations.expectedSize(); // Old API versions didn't account for conflict ranges when determining whether to throw transaction_too_large
|
||||
}
|
||||
|
||||
if (transactionSize > (options.customTransactionSizeLimit == 0 ? (uint64_t)CLIENT_KNOBS->TRANSACTION_SIZE_LIMIT : (uint64_t)options.customTransactionSizeLimit))
|
||||
if (transactionSize > options.sizeLimit) {
|
||||
return transaction_too_large();
|
||||
}
|
||||
|
||||
if( !readVersion.isValid() )
|
||||
getReadVersion( GetReadVersionRequest::FLAG_CAUSAL_READ_RISKY ); // sets up readVersion field. We had no reads, so no need for (expensive) full causal consistency.
|
||||
@ -2994,6 +3004,11 @@ void Transaction::setOption( FDBTransactionOptions::Option option, Optional<Stri
|
||||
options.maxBackoff = extractIntOption(value, 0, std::numeric_limits<int32_t>::max()) / 1000.0;
|
||||
break;
|
||||
|
||||
case FDBTransactionOptions::SIZE_LIMIT:
|
||||
validateOptionValue(value, true);
|
||||
options.sizeLimit = extractIntOption(value, 32, CLIENT_KNOBS->TRANSACTION_SIZE_LIMIT);
|
||||
break;
|
||||
|
||||
case FDBTransactionOptions::LOCK_AWARE:
|
||||
validateOptionValue(value, false);
|
||||
options.lockAware = true;
|
||||
|
@ -147,7 +147,7 @@ struct TransactionOptions {
|
||||
double maxBackoff;
|
||||
uint32_t maxRetries;
|
||||
uint32_t getReadVersionFlags;
|
||||
uint32_t customTransactionSizeLimit;
|
||||
uint32_t sizeLimit;
|
||||
bool checkWritesEnabled : 1;
|
||||
bool causalWriteRisky : 1;
|
||||
bool commitOnFirstProxy : 1;
|
||||
|
@ -126,7 +126,7 @@ public:
|
||||
|
||||
void getWriteConflicts( KeyRangeMap<bool> *result );
|
||||
|
||||
Database getDatabase() {
|
||||
Database getDatabase() const {
|
||||
return tr.getDatabase();
|
||||
}
|
||||
private:
|
||||
|
@ -155,6 +155,9 @@ description is not currently required but encouraged.
|
||||
<Option name="transaction_max_retry_delay" code="502"
|
||||
paramType="Int" paramDescription="value in milliseconds of maximum delay"
|
||||
description="Set the maximum amount of backoff delay incurred in the call to ``onError`` if the error is retryable. This sets the ``max_retry_delay`` option of each transaction created by this database. See the transaction option description for more information." />
|
||||
<Option name="transaction_size_limit" code="503"
|
||||
paramType="Int" paramDescription="value in bytes"
|
||||
description="Set the maximum transaction size which, if exceeded, will cause the transaction to be cancelled. Default to 10,000,000 bytes." />
|
||||
<Option name="snapshot_ryw_enable" code="26"
|
||||
description="Snapshot read operations will see the results of writes done in the same transaction. This is the default behavior." />
|
||||
<Option name="snapshot_ryw_disable" code="27"
|
||||
@ -210,7 +213,10 @@ description is not currently required but encouraged.
|
||||
<Option name="max_retry_delay" code="502"
|
||||
paramType="Int" paramDescription="value in milliseconds of maximum delay"
|
||||
description="Set the maximum amount of backoff delay incurred in the call to ``onError`` if the error is retryable. Defaults to 1000 ms. Valid parameter values are ``[0, INT_MAX]``. If the maximum retry delay is less than the current retry delay of the transaction, then the current retry delay will be clamped to the maximum retry delay. Prior to API version 610, like all other transaction options, the maximum retry delay must be reset after a call to ``onError``. If the API version is 610 or greater, the retry limit is not reset after an ``onError`` call. Note that at all API versions, it is safe and legal to set the maximum retry delay each time the transaction begins, so most code written assuming the older behavior can be upgraded to the newer behavior without requiring any modification, and the caller is not required to implement special logic in retry loops to only conditionally set this option."/>
|
||||
<Option name="snapshot_ryw_enable" code="600"
|
||||
<Option name="size_limit" code="503"
|
||||
paramType="Int" paramDescription="value in bytes"
|
||||
description="Set the maximum transaction size which, if exceeded, will cause the transaction to be cancelled. Valid parameter values are ``[32, 10,000,000]```." />
|
||||
<Option name="snapshot_ryw_enable" code="600"
|
||||
description="Snapshot read operations will see the results of writes done in the same transaction. This is the default behavior." />
|
||||
<Option name="snapshot_ryw_disable" code="601"
|
||||
description="Snapshot read operations will not see the results of writes done in the same transaction. This was the default behavior prior to API version 300." />
|
||||
|
@ -159,7 +159,7 @@ ACTOR Future<Void> localGenerationReg( GenerationRegInterface interf, OnDemandSt
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE("/fdbserver/Coordination/localGenerationReg/simple") {
|
||||
state GenerationRegInterface reg;
|
||||
|
Loading…
x
Reference in New Issue
Block a user