Layer 2: Storage
Single-purpose storage interfaces. Each store does one thing.
JournalStore
SQL statement buffer for write-ahead logging.
ftm_lakehouse.storage.JournalStore = SqlJournalStore
module-attribute
ParquetStore
Delta Lake parquet storage for statements, partitioned by (shard, bucket, origin). Writes are append-only; deduplication, first_seen folding, and tombstone reaping happen in three independent async ops (compact / merge / vacuum), all coordinated by a dataset-wide write fence.
ftm_lakehouse.storage.ParquetStore
Bases: LakehouseApiMixin
Single Delta Lake table (per dataset) partitioned by (shard, bucket,
origin).
Writes are append-only: append sorts a per-partition batch in memory
and writes one parquet file. Reads delegate to an ftmq LakeStore with
view_filter=deleted_at IS NULL (filters tombstones at query time;
merge drops them physically once past grace).
Source code in ftm_lakehouse/storage/parquet.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
exists
property
Check existence of deltatable
version
property
Current version of the main Delta table.
append(batch)
Append a sorted batch of statements.
The batch should be scoped to a single shard for write efficiency
(one parquet file per (shard, bucket, origin) partition). The
method sorts by (bucket, origin, entity_id, id, last_seen DESC)
then splits by bucket so each write_deltalake call uses the
bucket-appropriate writer_properties (small vs. large profile).
Duplicates land as separate rows and are reaped by :meth:merge.
Held under the dataset write fence so concurrent :meth:merge /
:meth:compact / :meth:vacuum can't tombstone an in-flight append.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Table
|
PyArrow table with the columns of
:data: |
required |
Source code in ftm_lakehouse/storage/parquet.py
compact()
Bin-pack small parquet files within each partition.
Cheap maintenance – Delta's OPTIMIZE compact only rewrites small
files into larger ones; it does not collapse duplicate rows or drop
tombstones (use :meth:merge for that). Held under the dataset write
fence (path.LOCK).
Source code in ftm_lakehouse/storage/parquet.py
destroy()
Destroy the deltalake by removing the transaction log in "_delta_log" directory. This is soft deleting, as the parquet files remain (but will be cleaned up on optimize --vacuum)
Source code in ftm_lakehouse/storage/parquet.py
export_csv(key, q=None)
Export statements to a sorted CSV file.
Source code in ftm_lakehouse/storage/parquet.py
get(entity_id)
Lookup an Entity by its ID
get_changed_entity_ids(since, schemata=None, prop=None)
Get entity IDs touched since a timestamp.
Catches both new / modified statements (first_seen >= since)
and deleted ones (deleted_at >= since) – the latter so the diff
consumer can emit DEL ops for entities whose tombstone landed after
the last diff state.
Source code in ftm_lakehouse/storage/parquet.py
get_statements(entity_id)
Query all live statements for a single entity.
Uses the shard partition for efficient pruning.
Source code in ftm_lakehouse/storage/parquet.py
merge(grace_period_days=None)
Collapse duplicates and reap expired tombstones, partition by partition.
For each (shard, bucket, origin) partition, runs the merge query
(keep latest row per id by last_seen DESC; fold first_seen
to the min; drop tombstones older than the grace cutoff) and atomically
overwrites that partition via partition_filters. Held under the
dataset write fence (path.LOCK).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grace_period_days
|
int | None
|
Override |
None
|
Source code in ftm_lakehouse/storage/parquet.py
query(q=None)
Query Entities from the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
Query | None
|
Optional Query object with filters |
None
|
Yields:
| Type | Description |
|---|---|
StatementEntities
|
StatementEntity objects matching the query |
Source code in ftm_lakehouse/storage/parquet.py
query_statements(q=None)
Query ordered Statements from the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
Select | None
|
Optional SQLAlchemy query (default: Query().sql.statements) |
None
|
Yields:
| Type | Description |
|---|---|
Statements
|
Statement objects matching the query |
Source code in ftm_lakehouse/storage/parquet.py
stats()
unlock()
Forcibly release the dataset write fence.
Operator escape hatch for the case where a writer process died
with the lock held (or an attacker held it on purpose). The lock
is just a file at {dataset_root}/.LOCK; this method deletes
it.
Use sparingly – breaking a lock that's still held by a live writer can corrupt a write in flight. Confirm no process is actively writing before running.
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
held. |
Source code in ftm_lakehouse/storage/parquet.py
vacuum(retention_hours=0)
Delete obsolete parquet files no longer referenced by the Delta log.
Tombstoned files (replaced by :meth:merge / :meth:compact) become
orphans on disk; vacuum prunes them once they're past
retention_hours. Held under the dataset write fence
(path.LOCK).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
retention_hours
|
int
|
Keep files newer than this many hours. |
0
|
Source code in ftm_lakehouse/storage/parquet.py
TagStore
Key-value freshness tracking.
ftm_lakehouse.storage.TagStore
Bases: Tags
Key-value store for freshness tracking.
Tags are timestamps stored as key-value pairs, used to track when resources were last updated and determine if processing is needed.
Layout: tags/{tenant}/{key}
This store has the "tags/{tenant}" key prefix set, so clients must use relative paths from there.
Source code in ftm_lakehouse/storage/tags.py
is_latest(key, dependencies)
Check if the tag is more recent than all dependencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Tag key to check |
required |
dependencies
|
Iterable[str]
|
Tag keys that this key depends on |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if key is newer than all dependencies, False otherwise |
Source code in ftm_lakehouse/storage/tags.py
set(key, timestamp=None)
Set a tag to the given timestamp (or now if not provided).
QueueStore
CRUD action queue for async processing.
ftm_lakehouse.storage.QueueStore
Bases: Queue
CRUD action queue for ordered mutation log.
All mutations (entity upsert/delete, file archive, mapping updates) go through this queue, ordered by UUID7 timestamp.
Layout: queue/{tenant}/{uuid7}.json
This store has the "queue/{tenant}" key prefix set, so clients must use relative paths from there.