Loading [MathJax]/extensions/tex2jax.js
LSST Applications g032c94a9f9+ac98094cfc,g04a91732dc+8f8ef39500,g07dc498a13+4eb283b00e,g0fba68d861+fe52cfea07,g1409bbee79+4eb283b00e,g1a7e361dbc+4eb283b00e,g1fd858c14a+21fedf7ac9,g208c678f98+a86e7897d4,g2c84ff76c0+22a6ac03ed,g35bb328faa+fcb1d3bbc8,g4d2262a081+a494e3f3d6,g4d39ba7253+3dc2658323,g4e0f332c67+c58e4b632d,g53246c7159+fcb1d3bbc8,g60b5630c4e+3dc2658323,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g8852436030+24b38c285b,g89139ef638+4eb283b00e,g8d6b6b353c+3dc2658323,g9125e01d80+fcb1d3bbc8,g989de1cb63+4eb283b00e,g9f33ca652e+abcb26939a,ga9baa6287d+3dc2658323,gaaedd4e678+4eb283b00e,gabe3b4be73+1e0a283bba,gb1101e3267+f06a32901e,gb58c049af0+f03b321e39,gb90eeb9370+5737ae2691,gcf25f946ba+24b38c285b,gd315a588df+81e3241efa,gd6cbbdb0b4+75aa4b1db4,gd9a9a58781+fcb1d3bbc8,gde0f65d7ad+ac7491eacb,ge278dab8ac+c61fbefdff,ge82c20c137+e12a08b75a,gf4a8514506+3f9a146d29,w.2025.11
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
legacy_config.py
Go to the documentation of this file.
1# This file is part of dax_apdb.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
22from __future__ import annotations
23
24from lsst.pex.config import ChoiceField, Field, ListField
25
26# If cassandra-driver is not there the module can still be imported.
27try:
28 import cassandra
29
30 CASSANDRA_IMPORTED = True
31except ImportError:
32 CASSANDRA_IMPORTED = False
33
34from .. import legacy_config
35from .._auth import DB_AUTH_PATH
36from . import config
37
38
40 """Configuration class for Cassandra-based APDB implementation."""
41
42 contact_points = ListField[str](
43 doc="The list of contact points to try connecting for cluster discovery.", default=["127.0.0.1"]
44 )
45 private_ips = ListField[str](doc="List of internal IP addresses for contact_points.", default=[])
46 port = Field[int](doc="Port number to connect to.", default=9042)
47 keyspace = Field[str](doc="Default keyspace for operations.", default="apdb")
48 username = Field[str](
49 doc=f"Cassandra user name, if empty then {DB_AUTH_PATH} has to provide it with password.",
50 default="",
51 )
52 read_consistency = Field[str](
53 doc="Name for consistency level of read operations, default: QUORUM, can be ONE.", default="QUORUM"
54 )
55 write_consistency = Field[str](
56 doc="Name for consistency level of write operations, default: QUORUM, can be ONE.", default="QUORUM"
57 )
58 read_timeout = Field[float](doc="Timeout in seconds for read operations.", default=120.0)
59 write_timeout = Field[float](doc="Timeout in seconds for write operations.", default=60.0)
60 remove_timeout = Field[float](doc="Timeout in seconds for remove operations.", default=600.0)
61 read_concurrency = Field[int](doc="Concurrency level for read operations.", default=500)
62 protocol_version = Field[int](
63 doc="Cassandra protocol version to use, default is V4",
64 default=cassandra.ProtocolVersion.V4 if CASSANDRA_IMPORTED else 4,
65 )
66 dia_object_columns = ListField[str](
67 doc="List of columns to read from DiaObject[Last], by default read all columns", default=[]
68 )
69 prefix = Field[str](doc="Prefix to add to table names", default="")
70 part_pixelization = ChoiceField[str](
71 allowed=dict(htm="HTM pixelization", q3c="Q3C pixelization", mq3c="MQ3C pixelization"),
72 doc="Pixelization used for partitioning index.",
73 default="mq3c",
74 )
75 part_pix_level = Field[int](doc="Pixelization level used for partitioning index.", default=11)
76 part_pix_max_ranges = Field[int](doc="Max number of ranges in pixelization envelope", default=128)
77 ra_dec_columns = ListField[str](default=["ra", "dec"], doc="Names of ra/dec columns in DiaObject table")
78 timer = Field[bool](doc="If True then print/log timing information", default=False)
79 time_partition_tables = Field[bool](
80 doc="Use per-partition tables for sources instead of partitioning by time", default=False
81 )
82 time_partition_days = Field[int](
83 doc=(
84 "Time partitioning granularity in days, this value must not be changed after database is "
85 "initialized"
86 ),
87 default=30,
88 )
89 time_partition_start = Field[str](
90 doc=(
91 "Starting time for per-partition tables, in yyyy-mm-ddThh:mm:ss format, in TAI. "
92 "This is used only when time_partition_tables is True."
93 ),
94 default="2018-12-01T00:00:00",
95 )
96 time_partition_end = Field[str](
97 doc=(
98 "Ending time for per-partition tables, in yyyy-mm-ddThh:mm:ss format, in TAI. "
99 "This is used only when time_partition_tables is True."
100 ),
101 default="2030-01-01T00:00:00",
102 )
103 query_per_time_part = Field[bool](
104 default=False,
105 doc=(
106 "If True then build separate query for each time partition, otherwise build one single query. "
107 "This is only used when time_partition_tables is False in schema config."
108 ),
109 )
110 query_per_spatial_part = Field[bool](
111 default=False,
112 doc="If True then build one query per spatial partition, otherwise build single query.",
113 )
114 use_insert_id_skips_diaobjects = Field[bool](
115 default=False,
116 doc=(
117 "If True then do not store DiaObjects when use_insert_id is True "
118 "(DiaObjectsChunks has the same data)."
119 ),
120 )
121 idle_heartbeat_interval = Field[int](
122 doc=(
123 "Interval, in seconds, on which to heartbeat idle connections. "
124 "Zero (default) disables heartbeats."
125 ),
126 default=0,
127 )
128 idle_heartbeat_timeout = Field[int](
129 doc="Timeout, in seconds, on which the heartbeat wait for idle connection responses.",
130 default=30,
131 )
132
133 def to_model(self) -> config.ApdbCassandraConfig:
134 # Docstring inherited from base class.
135
136 # control_connection_timeout is not in the pex_config, but it is set as
137 # a default in init_database, so we use the same value here.
138 connection_config = config.ApdbCassandraConnectionConfig(
139 port=self.port,
140 private_ips=tuple(self.private_ips),
141 username=self.username,
142 read_consistency=self.read_consistency,
143 write_consistency=self.write_consistency,
144 read_timeout=self.read_timeout,
145 write_timeout=self.write_timeout,
146 remove_timeout=self.remove_timeout,
147 read_concurrency=self.read_concurrency,
148 protocol_version=self.protocol_version,
149 extra_parameters={
150 "idle_heartbeat_interval": self.idle_heartbeat_interval,
151 "idle_heartbeat_timeout": self.idle_heartbeat_timeout,
152 "control_connection_timeout": 100,
153 },
154 )
155 partitioning_config = config.ApdbCassandraPartitioningConfig(
156 part_pixelization=self.part_pixelization,
157 part_pix_level=self.part_pix_level,
158 part_pix_max_ranges=self.part_pix_max_ranges,
159 time_partition_tables=self.time_partition_tables,
160 time_partition_days=self.time_partition_days,
161 time_partition_start=self.time_partition_start,
162 time_partition_end=self.time_partition_end,
163 query_per_time_part=self.query_per_time_part,
164 query_per_spatial_part=self.query_per_spatial_part,
165 )
166 new_config = config.ApdbCassandraConfig(
167 schema_file=self.schema_file,
168 schema_name=self.schema_name,
169 read_sources_months=self.read_sources_months,
170 read_forced_sources_months=self.read_forced_sources_months,
171 enable_replica=self.use_insert_id,
172 replica_chunk_seconds=self.replica_chunk_seconds,
173 contact_points=tuple(self.contact_points),
174 keyspace=self.keyspace,
175 connection_config=connection_config,
176 partitioning=partitioning_config,
177 dia_object_columns=list(self.dia_object_columns),
178 prefix=self.prefix,
179 ra_dec_columns=(self.ra_dec_columns[0], self.ra_dec_columns[1]),
180 replica_skips_diaobjects=self.use_insert_id_skips_diaobjects,
181 )
182 return new_config