Manager
SearchVersion
¶
Bases: Enum
Indicator for the SplitgillDatabase.search method as to which version of the data you would like to search.
Source code in splitgill/manager.py
92 93 94 95 96 97 98 99 100 101 | |
SplitgillClient
¶
Splitgill client class which holds a mongo connection, an elasticsearch connection and any other general information Splitgill needs to manage the databases.
Source code in splitgill/manager.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
get_data_collection(name)
¶
Returns the data collection for the given Splitgill database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the name of the Splitgill database |
required |
Returns:
| Type | Description |
|---|---|
Collection
|
a pymongo Collection object |
Source code in splitgill/manager.py
74 75 76 77 78 79 80 81 | |
get_database(name)
¶
Returns a SplitgillDatabase object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the name of the database |
required |
Returns:
| Type | Description |
|---|---|
SplitgillDatabase
|
a new SplitgillDatabase object |
Source code in splitgill/manager.py
49 50 51 52 53 54 55 56 | |
get_lock_collection()
¶
Returns the locks collection.
Returns:
| Type | Description |
|---|---|
Collection
|
a pymongo Collection object |
Source code in splitgill/manager.py
83 84 85 86 87 88 89 | |
get_mongo_database()
¶
Returns the MongoDB database in use.
Returns:
| Type | Description |
|---|---|
Database
|
a pymongo Database object |
Source code in splitgill/manager.py
58 59 60 61 62 63 64 | |
get_options_collection()
¶
Returns the options collection.
Returns:
| Type | Description |
|---|---|
Collection
|
a pymongo Collection object |
Source code in splitgill/manager.py
66 67 68 69 70 71 72 | |
SplitgillDatabase
¶
Represents a single set of data to be managed by Splitgill.
Under the hood, this data will exist in several MongoDB collections and Elasticsearch indices, but this object provides an abstraction layer to access all of that from one object.
Source code in splitgill/manager.py
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 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | |
__init__(name, client)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the name of the database, needs to be a valid MongoDB collection name and a valid Elasticsearch index name |
required |
client
|
SplitgillClient
|
a SplitgillClient object |
required |
Source code in splitgill/manager.py
113 114 115 116 117 118 119 120 121 122 123 124 | |
commit()
¶
Commits the currently uncommitted data and options changes for this database. All new data/options will be given the same version which is the current time. If no changes were made, None is returned, otherwise the new version is returned.
If a commit is already ongoing this will raise an AlreadyLocked exception.
Returns:
| Type | Description |
|---|---|
Optional[int]
|
the new version or None if no uncommitted changes were found |
Source code in splitgill/manager.py
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 | |
get_arc_status()
¶
Get the status of the latest archive index in use by this database in Elasticsearch. Old versions of records are stored in the archive (arc) indices using an append strategy. This starts with arc-0 and after this arc is filled moves on to arc-1 and so on. This method returns the index of the most recently used arc (i.e. the arc with the highest index number) and the number of documents in it.
Returns:
| Type | Description |
|---|---|
ArcStatus
|
an ArcStatus object |
Source code in splitgill/manager.py
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 | |
get_committed_version()
¶
Returns the latest committed version of the data or config (whichever is higher). If no records or options exist, or if neither has any committed values, None is returned.
Returns:
| Type | Description |
|---|---|
Optional[int]
|
the max version or None |
Source code in splitgill/manager.py
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 | |
get_current_indices()
¶
Returns a list of the indices currently in use by this database in Elasticsearch sorted in ascending alphabetical order.
Returns:
| Type | Description |
|---|---|
List[str]
|
a list of index names |
Source code in splitgill/manager.py
126 127 128 129 130 131 132 133 134 | |
get_data_fields(version=None, query=None, **iter_terms_kwargs)
¶
Retrieves the available data fields for this database, optionally at the given version with the given query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
Optional[int]
|
the version to find data fields at, if None, the latest data is searched |
None
|
query
|
Optional[Query]
|
the query to filter records with before finding the data fields, if None, all record data is considered |
None
|
iter_terms_kwargs
|
kwargs passed directly to iter_terms (e.g. chunk_size, sample_probability) |
{}
|
Returns:
| Type | Description |
|---|---|
List[DataField]
|
a list of DataField objects with the most frequent field first |
Source code in splitgill/manager.py
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 | |
get_elasticsearch_version()
¶
Returns the latest version found in the Elasticsearch indices for this database. If no records exist in any index, None is returned. This method checks both the maximum value in the version field and the next field. Checking the next field accounts for updates that only include deletions.
Returns:
| Type | Description |
|---|---|
Optional[int]
|
the max version or None |
Source code in splitgill/manager.py
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 | |
get_field_names()
¶
Retrieves a list of field names from the latest index mapping.
Does not take any version or query parameters; simply returns all the "data." fields available on the index, along with their available types. All relevant type counts are set to 1 to enable use of e.g. .is_text(). Use get_data_fields or get_parsed_fields if you need accurate counts, or to filter by version or query.
Source code in splitgill/manager.py
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | |
get_options(include_uncommitted=False)
¶
Retrieve all the parsing options configured for this database in a dict mapping int versions to ParsingOptions objects. Use the include_uncommitted parameter to indicate whether to include the uncommitted options or not.
Returns:
| Type | Description |
|---|---|
Dict[int, ParsingOptions]
|
a dict of versions and options |
Source code in splitgill/manager.py
414 415 416 417 418 419 420 421 422 423 424 425 426 | |
get_parsed_fields(version=None, query=None, **iter_terms_kwargs)
¶
Retrieves the available parsed fields for this database, optionally at the given version with the given query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
Optional[int]
|
the version to find parsed fields at, if None, the latest data is searched |
None
|
query
|
Optional[Query]
|
the query to filter records with before finding the parsed fields, if None, all record data is considered |
None
|
iter_terms_kwargs
|
kwargs passed directly to iter_terms (e.g. chunk_size, sample_probability) |
{}
|
Returns:
| Type | Description |
|---|---|
List[ParsedField]
|
a list of ParsedField objects with the most frequent field first |
Source code in splitgill/manager.py
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 | |
get_rounded_version(version)
¶
Given a target version, rounds the version down to the nearest available version. This in effect returns the version of the data that is application to the given target version.
If the target version is below the earliest version or this database's indexed data, or, no indexed versions are available, None is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
int
|
the target version |
required |
Returns:
| Type | Description |
|---|---|
Optional[int]
|
a version or None |
Source code in splitgill/manager.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
get_version_changed_counts()
¶
Retrieves the available versions and the number of documents that have changed in the database with that version. Changes can be additions, modifications, or deletions.
Returns:
| Type | Description |
|---|---|
Dict[int, int]
|
versions and associated change counts |
Source code in splitgill/manager.py
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 | |
get_versions()
¶
Returns a list of the available versions that have been indexed into Elasticsearch for this database. The versions are in ascending order and will be retrieved from both the version and next document fields to ensure we capture all versions.
Returns:
| Type | Description |
|---|---|
List[int]
|
the available versions in ascending order |
Source code in splitgill/manager.py
628 629 630 631 632 633 634 635 636 637 | |
has_data()
¶
Returns True if there is at least one committed record in this database, otherwise returns False. Note that this ignored options.
Returns:
| Type | Description |
|---|---|
bool
|
True if there is data, False if not |
Source code in splitgill/manager.py
232 233 234 235 236 237 238 239 | |
has_options()
¶
Returns True if there is at least one committed options in this database, otherwise returns False. Note that this ignored data.
Returns:
| Type | Description |
|---|---|
bool
|
True if there is options, False if not |
Source code in splitgill/manager.py
241 242 243 244 245 246 247 248 | |
has_uncommitted_data()
¶
Check if there are any uncommitted records stored against this database.
Returns:
| Type | Description |
|---|---|
bool
|
returns True if there are any uncommitted records, False if not |
Source code in splitgill/manager.py
398 399 400 401 402 403 404 | |
has_uncommitted_options()
¶
Check if there are any uncommitted options stored against this database.
Returns:
| Type | Description |
|---|---|
bool
|
returns True if there are any uncommitted options, False if not |
Source code in splitgill/manager.py
406 407 408 409 410 411 412 | |
ingest(records, commit=True, modified_field=None)
¶
Ingests the given records to the database. This only adds the records to the MongoDB data collection, it doesn't trigger the indexing of this new data into the Elasticsearch cluster. All data will be added with a None version unless the commit parameter is True in which case a version will be assigned.
Use the commit keyword argument to either close the "transaction" after writing these records or leave it open. By default, the "transaction" is committed before the method returns, and the version is set then.
If an error occurs, the "transaction" will not be committed, but the changes will not be rolled back.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records
|
Iterable[Record]
|
the records to add. These will be added in batches, so it is safe to pass a very large stream of records |
required |
commit
|
whether to commit the data added with a new version after writing the records. Default: True. |
True
|
|
modified_field
|
Optional[str]
|
a field name which, if the only changes in the record data are in this field means the changes will be ignored. As you can probably guess from the name, the root reason for this parameter existing is to avoid committing a new version of a record when all that has happened is the record has been touched and the modified field's date value updated even though the rest of the record remains the same. Default: None, meaning all fields are checked for changes. |
None
|
Returns:
| Type | Description |
|---|---|
IngestResult
|
returns a IngestResult object |
Source code in splitgill/manager.py
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 | |
iter_records(**find_kwargs)
¶
Yields MongoRecord objects matching the given find kwargs. As you can probably guess, the find_kwargs argument is just passed directly to PyMongo's find method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
find_kwargs
|
args to pass to the data collection's find method |
{}
|
Returns:
| Type | Description |
|---|---|
Iterable[MongoRecord]
|
yields matching MongoRecord objects |
Source code in splitgill/manager.py
428 429 430 431 432 433 434 435 436 437 438 439 | |
resync_arcs(bulk_options=None)
¶
Resynchronises all the arc indices. The arc indices are deleted first and then resynced. The latest index isn't touched.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bulk_options
|
Optional[BulkOptions]
|
options determining how the bulk operations are sent to Elasticsearch |
None
|
Returns:
| Type | Description |
|---|---|
WriteResult
|
a WriteResult object |
Source code in splitgill/manager.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | |
rollback_options()
¶
Remove any uncommitted option changes.
There should only ever be one, but this deletes them all ensuring everything is clean and tidy.
Returns:
| Type | Description |
|---|---|
int
|
the number of documents deleted |
Source code in splitgill/manager.py
375 376 377 378 379 380 381 382 383 384 | |
rollback_records()
¶
Remove any uncommitted data changes.
This method has to interrogate every uncommitted record in the data collection to perform the rollback and therefore, depending on how much uncommitted data there is, may take a bit of time to run.
Source code in splitgill/manager.py
386 387 388 389 390 391 392 393 394 395 396 | |
search(version=SearchVersion.latest)
¶
Creates a Search DSL object to use on this database's indexed data. This Search object will be setup with the appropriate index and version filter depending on the given version parameter, and the Elasticsearch client object in use on this database.
If a version number is passed as the version parameter, it will be checked against the latest version available in Elasticsearch. If it is below the latest version available in Elasticsearch, all indices will be searched and a term filter will be used to get the right data. If the version is equal to or above the latest version available in Elasticsearch, the latest index will be searched and no version term filter will be used. This is for Elasticsearch performance and caching.
If version is not an int but is instead a SearchVersion, this is used to set the index on the search object. SearchVersion.latest sets the index to this database's latest index, whereas SearchVersion.all sets the index to a wildcard to search on all indices used by this database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
Union[SearchVersion, int]
|
the version to search at, this should either be a SearchVersion enum option or an int version. |
latest
|
Returns:
| Type | Description |
|---|---|
Search
|
a Search DSL object |
Source code in splitgill/manager.py
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 | |
sync(bulk_options=None, resync=False)
¶
Synchronise the data/options in MongoDB with the data in Elasticsearch by updating the latest and old data indices as required.
To find the data that needs to be updated, the current version of the data in MongoDB is compared to the current version of the data in Elasticsearch, and the two are synced (assuming MongoDB's version is <= Elasticsearch).
While the data is being indexed, refreshing is paused on this database's indexes and only resumed once all the data has been indexed. If an error occurs during indexing then the refresh interval is not reset meaning the updates that have made it to Elasticsearch will not impact searches until a refresh is triggered, or the refresh interval is reset. This kinda makes this function transactional. If no errors occur, the refresh interval is reset (along with the replica count) and a refresh is called. This means that if this function returns successfully, the data updated by it will be immediately available for searches.
Note that if resync=True, the arc indices will be deleted before reindexing begins! The latest index is not deleted as the documents in the latest index have IDs so can be directly replaced.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bulk_options
|
Optional[BulkOptions]
|
options determining how the bulk operations are sent to Elasticsearch |
None
|
resync
|
bool
|
whether to resync all records with Elasticsearch regardless of the currently synced version. This won't delete any data in the latest index as those records are replaced during resync, but any arc indices will be deleted prior to re-indexing. |
False
|
Returns:
| Type | Description |
|---|---|
WriteResult
|
a WriteResult object |
Source code in splitgill/manager.py
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 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 | |
update_options(options, commit=True)
¶
Update the parsing options for this database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
ParsingOptions
|
the new parsing options |
required |
commit
|
whether to commit the new config added with a new version after writing the config. Default: True. |
True
|
Returns:
| Type | Description |
|---|---|
Optional[int]
|
returns the new version if a commit happened, otherwise None. If a commit was requested but nothing was changed, None is returned. |
Source code in splitgill/manager.py
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 | |