1#  Copyright 2015 - present MongoDB, Inc.
2#
3#  Licensed under the Apache License, Version 2.0 (the "License");
4#  you may not use this file except in compliance with the License.
5#  You may obtain a copy of the License at
6#
7#  http://www.apache.org/licenses/LICENSE-2.0
8#
9#  Unless required by applicable law or agreed to in writing, software
10#  distributed under the License is distributed on an "AS IS" BASIS,
11#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12#  See the License for the specific language governing permissions and
13#  limitations under the License.
14
15use strict;
16use warnings;
17
18package MongoDB::_Constants;
19
20# Common MongoDB driver constants
21
22use version;
23our $VERSION = 'v2.2.2';
24
25use Exporter 5.57 qw/import/;
26use Config;
27
28my $CONSTANTS;
29
30BEGIN {
31    $CONSTANTS = {
32        COOLDOWN_SECS                => 5,
33        CURSOR_ZERO                  => "\0" x 8,
34        EPOCH                        => 0,
35        HAS_INT64                    => $Config{use64bitint},
36        IDLE_WRITE_PERIOD_SEC        => 10,
37        MAX_BSON_OBJECT_SIZE         => 4_194_304,
38        MAX_GRIDFS_BATCH_SIZE        => 16_777_216,                 # 16MiB
39        MAX_BSON_WIRE_SIZE           => 16_793_600,                 # 16MiB + 16KiB
40        MAX_WIRE_VERSION             => 8,
41        MAX_WRITE_BATCH_SIZE         => 1000,
42        MIN_HEARTBEAT_FREQUENCY_SEC  => .5,
43        MIN_HEARTBEAT_FREQUENCY_USEC => 500_000,                    # 500ms, not configurable
44        MIN_KEYED_DOC_LENGTH         => 8,
45        MIN_SERVER_VERSION           => "2.4.0",
46        MIN_WIRE_VERSION             => 0,
47        RESCAN_SRV_FREQUENCY_SEC      => $ENV{TEST_MONGO_RESCAN_SRV_FREQUENCY_SEC} || 60,
48        NO_JOURNAL_RE                => qr/^journaling not enabled/,
49        NO_REPLICATION_RE          => qr/^no replication has been enabled/,
50        P_INT32                    => $] lt '5.010' ? 'l' : 'l<',
51        SMALLEST_MAX_STALENESS_SEC => 90,
52        WITH_ASSERTS               => $ENV{PERL_MONGO_WITH_ASSERTS},
53        # Transaction state tracking
54        TXN_NONE                    => 'none',
55        TXN_STARTING                => 'starting',
56        TXN_IN_PROGRESS             => 'in_progress',
57        TXN_COMMITTED               => 'committed',
58        TXN_ABORTED                 => 'aborted',
59        TXN_WTIMEOUT_RETRY_DEFAULT  => 10_000,  # 10 seconds
60        TXN_TRANSIENT_ERROR_MSG     => 'TransientTransactionError',
61        TXN_UNKNOWN_COMMIT_MSG      => 'UnknownTransactionCommitResult',
62        # From the Convenient API for Transactions spec, with_transaction must
63        # halt retries after 120 seconds.
64        # This limit is non-configurable and was chosen to be twice the 60 second
65        # default value of MongoDB's `transactionLifetimeLimitSeconds` parameter.
66        WITH_TXN_RETRY_TIME_LIMIT   => 120, # seconds
67    };
68}
69
70use constant $CONSTANTS;
71
72our @EXPORT = keys %$CONSTANTS;
73
741;
75