Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get number of shards and replicas? #84

Closed
nook24 opened this issue Mar 2, 2020 · 3 comments
Closed

How to get number of shards and replicas? #84

nook24 opened this issue Mar 2, 2020 · 3 comments
Assignees

Comments

@nook24
Copy link

nook24 commented Mar 2, 2020

Hi everyone
this is a follow up to my last issue #75.
I'm still working on my automatically schema dump and update script.

This time I try to query the current amount of shards, partition options and number of replicas.
Unfortunately the result of $table->getOptions() is empty. Thats my code:

$connectionParams = [
    'user'        => null,
    'password'    => null,
    'host'        => '127.0.0.1',
    'port'        => 4200,
    'driverClass' => 'Crate\DBAL\Driver\PDOCrate\Driver',
];
$connection = DriverManager::getConnection($connectionParams);
$platform = $connection->getDatabasePlatform();

$SchemaManager = $connection->getSchemaManager();

$schema = $SchemaManager->createSchema();

foreach ($schema->getTables() as $table) {
    print_r($table->getOptions());
}

My results

Array
(
    [create_options] => Array
        (
        )

)
Array
(
    [create_options] => Array
        (
        )

)

This is my schema: https://github.com/statusengine/worker/blob/master/lib/crateDB.sql
In the docs I only found how to set the table options - not how to read theme.

I'm on version crate-dbal 2.2.0 and CrateDB 4.1.2

@autophagy
Copy link
Contributor

Hi @nook24,

I don't believe this is actually possible in the current crate-dbal - we use the underlying DBAL library to get table details:

https://github.com/doctrine/dbal/blob/4c03ed81471c62f178581eb325339a3c34f3b71a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php#L270

Here, when getting table information, it only retrieves columns, indexes and foreign keys - no options. I'll look into extending to this, to see if we can retrieve the options of a table alongside the other information.

@autophagy
Copy link
Contributor

Hi @nook24 - I've just released version 2.3.0 of the DBAL driver, which contains a feature to retrieve CrateDB specific table options when you retrieve tables from createSchema(). So your above code would result in something like this:

Array
(
    [create_options] => Array
        (
        )

    [sharding_routing_column] => id
    [sharding_num_shards] => 6
    [partition_columns] => Array
        (
            [0] => parted
            [1] => date
        )

    [table_options] => Array
        (
            [codec] => default
            [routing.allocation.include] => 
            [routing.allocation.require] => 
            [routing.allocation.exclude] => 
            [routing.allocation.enable] => all
            [routing.allocation.total_shards_per_node] => -1
            [mapping.total_fields.limit] => 1000
            [refresh_interval] => 1000
            [translog.flush_threshold_size] => 536870912
            [translog.sync_interval] => 5000
            [translog.durability] => REQUEST
            [blocks.metadata] => 
            [blocks.read] => 
            [blocks.read_only] => 
            [blocks.write] => 
            [merge.scheduler.max_thread_count] => 
            [merge.scheduler.max_merge_count] => 
            [store.type] => fs
            [unassigned.node_left.delayed_timeout] => 60000
            [write.wait_for_active_shards] => ALL
            [warmer.enabled] => 1
            [number_of_replicas] => 0-2
            [column_policy] => strict
        )

)

I'll close this issue now, as I believe it is now resolved. But if you encounter further issues, please don't hesitate to reopen it. 🚀

Thanks again for reporting this!

@nook24
Copy link
Author

nook24 commented Jun 20, 2020

Works as expected, many thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants