Static Public Attributes | |
| string | HOST "localhost" |
| string | SERVICE "11810" |
| string | USER "" |
| string | PSW "" |
SequoiaDB Client Driver
The client support interfaces to connect to SequoiaDB.
In order to connect to SequoiaDB, you need use the class first.
And you should make sure the instance of it released when you don't use it
any more.
All operation need deal with the error code returned first, if it has.
Every error code is not SDB_OK(or 0), it means something error has appeared,
and user should deal with it according the meaning of error code printed.
@version: execute to get version
>>> import pysequoiadb
>>> print pysequoiadb.get_version()
@notice : The dict of built-in Python is hashed and non-ordered. so the
element in dict may not the order we make it. we make a dict and
print it like this:
...
>>> a = {"avg_age":24, "major":"computer science"}
>>> a
>>> {'major': 'computer science', 'avg_age': 24}
...
the elements order it is not we make it!!
therefore, we use bson.SON to make the order-sensitive dict if the
order is important such as operations in "$sort", "$group",
"split_by_condition", "aggregate","create_collection"...
In every scene which the order is important, please make it using
bson.SON and list. It is a subclass of built-in dict
and order-sensitive
| def pysequoiadb.client.client.__init__ | ( | self, | |
host = None, |
|||
service = None, |
|||
user = None, |
|||
psw = None, |
|||
ssl = False |
|||
| ) |
initialize when product a object.
it will try to connect to SequoiaDB using host and port given,
localhost and 11810 are the default value of host and port,
user and password are "".
Parameters:
Name Type Info:
host str The hostname or IP address of dbserver,
if None, "localhost" will be insteaded
service str/int The service name or port number of dbserver,
if None, "11810" will be insteaded
user str The user name to access to database,
if None, "" will be insteaded
psw str The user password to access to database,
if None, "" will be insteaded
ssl bool decide to use ssl or not, default is False.
Exceptions:
pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.__del__ | ( | self | ) |
release resource when del called. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.__getattr__ | ( | self, | |
| name | |||
| ) |
support client.cs to access to collection space.
eg.
cc = client()
cs = cc.test # access to collection space named 'test'
and we should pass '__members__' and '__methods__',
becasue dir(cc) will invoke __getattr__("__members__") and
__getattr__("__methods__").
if success, a collection object will be returned, or None.
Exceptions:
pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.__getitem__ | ( | self, | |
| name | |||
| ) |
support [] to access to collection space. eg. cc = client() cs = cc['test'] # access to collection space named 'test'. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.backup_offline | ( | self, | |
options = None |
|||
| ) |
Backup the whole database or specified replica group.
Parameters:
Name Type Info:
options dict Contains a series of backup configuration
information. Backup the whole cluster if None.
The "options" contains 5 options as below.
All the elements in options are optional.
eg:
{ "GroupName":["rgName1", "rgName2"],
"Path":"/opt/sequoiadb/backup",
"Name":"backupName", "Description":description,
"EnsureInc":true, "OverWrite":true }
See Info as below.
Exceptions:
pysequoiadb.error.SDBBaseError
Info:
GroupName : The replica groups which to be backuped.
Path : The backup path, if not assign, use the backup path assigned in configuration file.
Name : The name for the backup.
Description : The description for the backup.
EnsureInc : Whether execute increment synchronization,
default to be false.
OverWrite : Whether overwrite the old backup file,
default to be false.
| def pysequoiadb.client.client.cancel_task | ( | self, | |
| task_id, | |||
| is_async | |||
| ) |
Cancel the specified task.
Parameters:
Name Type Info:
task_id long The task id to be canceled.
is_async bool The operation "cancel task" is async or not,
"True" for async, "False" for sync.
Exceptions:
pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.close_all_cursors | ( | self | ) |
Close all the cursors in current thread, we can't use those cursors to get data again. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.connect | ( | self, | |
| host, | |||
| service, | |||
| kwargs | |||
| ) |
connect to specified database Parameters: Name Type Info: host str The host name or IP address of database server. service int/str The service name of database server. **kwargs Useful options are below: - user str The user name to access to database. - password str The user password to access to database. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.connect_to_hosts | ( | self, | |
| hosts, | |||
| kwargs | |||
| ) |
try to connect a host in specified hosts
Parameters:
Name Type Info:
hosts list The list contains hosts.
eg.
[ {'host':'localhost', 'service':'11810'},
{'host':'192.168.10.30', 'service':'11810'},
{'host':'192.168.20.63', 'service':11810}, ]
**kwargs Useful options are below:
- user str The user name to access to database.
- password str The user password to access to database.
- policy str The policy of select hosts. it must be string
of 'random' or 'local_first' or 'one_by_one', default is 'random'.
'local_first' will choose local host firstly,
then use 'random' if no local host.
Exceptions:
pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.create_cata_replica_group | ( | self, | |
| host, | |||
| service, | |||
| path, | |||
configure = None |
|||
| ) |
Create catalog replica group. Parameters: Name Type Info: host str The hostname for the catalog replica group. service str The service name for the catalog replica group. path str The path for the catalog replica group. configure dict The optional configurations for the catalog replica group. Return values: The created catalog replicagroup object. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.create_collection_space | ( | self, | |
| cs_name, | |||
options = 0 |
|||
| ) |
Create collection space with specified pagesize.
Parameters:
Name Type Info:
cs_name str The name of collection space to be created.
options int/dict The options to create collection space.
When type is int, means setting PageSize.
-PageSize int The page size of collection space. See Info
as below.
-Domain str The domain of collection space to belongs
-LobPageSize int The page size when stored lob, see Info as below
Return values:
collection space object created.
Exceptions:
pysequoiadb.error.SDBBaseError
Info:
valid page size value:
0 : 64k default page size
4096 : 4k
8192 : 8k
16384 : 16k
32768 : 32k
65536 : 64k
valid LOB page size value:
0 : 256k default Lob page size
4096 : 4k
8192 : 8k
16384 : 16k
32768 : 32k
65536 : 64k
131072 : 128k
262144 : 256k
524288 : 512k
| def pysequoiadb.client.client.create_coord_replica_group | ( | self | ) |
Create coordinator replica group. Return values: The created coordinator replicagroup object. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.create_domain | ( | self, | |
| domain_name, | |||
options = None |
|||
| ) |
Create domain.
Parameters:
Name Type Info
domain_name str The domain name.
options dict The options for the domain. The options are as below:
Groups: the list of the replica groups' names which the domain is going to contain.
eg: { "Groups": [ "group1", "group2", "group3" ] }
If this argument is not included, the domain will contain all replica groups in the cluster.
AutoSplit: If this option is set to be true, while creating collection(ShardingType is "hash") in this domain,
the data of this collection will be split(hash split) into all the groups in this domain automatically.
However, it won't automatically split data into those groups which were add into this domain later.
eg: { "Groups": [ "group1", "group2", "group3" ], "AutoSplit: true" }
Return values:
The created domain object.
Exceptions:
pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.create_procedure | ( | self, | |
| code | |||
| ) |
Create a store procedures Parameters: Name Type Info: code str The JS code of store procedures. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.create_replica_cata_group | ( | self, | |
| host, | |||
| service, | |||
| path, | |||
configure = None |
|||
| ) |
Use create_cata_replica_group instead.
| def pysequoiadb.client.client.create_replica_group | ( | self, | |
| group_name | |||
| ) |
Create the specified replica group. Parameters: Name Type Info: group_name str The name of replica group to be created. Return values: The created replicagroup object. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.create_user | ( | self, | |
| name, | |||
| psw | |||
| ) |
Add an user in current database. Parameters: Name Type Info: name str The name of user to be created. psw str The password of user to be created. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.disconnect | ( | self | ) |
disconnect to current server. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.drop_collection_space | ( | self, | |
| cs_name | |||
| ) |
Remove the specified collection space. Parameters: Name Type Info: cs_name str The name of collection space to be dropped Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.drop_domain | ( | self, | |
| domain_name | |||
| ) |
Drop the specified domain.
Parameters:
Name Type Info
domain_name str The domain name.
Exceptions:
pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.eval_procedure | ( | self, | |
| name | |||
| ) |
Eval a func. Parameters: Name Type Info: name str The name of store procedure. Return values: cursor object of current eval. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.exec_sql | ( | self, | |
| sql | |||
| ) |
Executing SQL command for query. Parameters: Name Type Info: sql str The SQL command. Return values: a cursor object of matching documents. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.exec_update | ( | self, | |
| sql | |||
| ) |
Executing SQL command for updating, inserting and deleting. Parameters: Name Type Info: sql str The SQL command. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.flush_configure | ( | self, | |
| options | |||
| ) |
Flush the options to configure file.
Parameters:
Name Type Info:
options dict The configure information, pass {"Global":true} or
{"Global":false} In cluster environment, passing
{"Global":true} will flush data's and catalog's
configuration file, while passing {"Global":false} will
flush coord's configuration file. In stand-alone
environment, both them have the same behaviour.
Exceptions:
pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.get_cata_replica_group | ( | self | ) |
Get catalog replica group Return values: The catalog replicagroup object. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.get_collection | ( | self, | |
| cl_full_name | |||
| ) |
Get the specified collection. Parameters: Name Type Info: cl_full_name str The full name of collection Return values: a collection object of query. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.get_collection_space | ( | self, | |
| cs_name | |||
| ) |
Get the specified collection space. Parameters: Name Type Info: cs_name str The name of collection space. Return values: a collection space object of query. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.get_coord_replica_group | ( | self | ) |
Get coordinator replica group Return values: The coordinator replicagroup object. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.get_domain | ( | self, | |
| domain_name | |||
| ) |
Get the specified domain.
Parameters:
Name Type Info
domain_name str The domain name.
Return values:
The specified domain object.
Exceptions:
pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.get_list | ( | self, | |
| list_type, | |||
| kwargs | |||
| ) |
Get information of the specified type.
Parameters:
Name Type Info:
list_type int Type of list option, see Info as below.
**kwargs Useful options are below
- condition dict The matching rule, match all the documents
if None.
- selector dict The selective rule, return the whole
documents if None.
- order_by dict The ordered rule, never sort if None.
Return values:
a cursor object of query
Exceptions:
pysequoiadb.error.SDBBaseError
Info:
list type:
0 : Get all contexts list
1 : Get contexts list for the current session
2 : Get all sessions list
3 : Get the current session
4 : Get all collections list
5 : Get all collection spaces' list
6 : Get storage units list
7 : Get replicaGroup list ( only applicable in sharding env )
8 : Get store procedure list
9 : Get domains list
10 : Get tasks list
11 : Get transactions list
12 : Get current session's transaction list
129 : Get collection space list in domain
130 : Get collection list in domain
| def pysequoiadb.client.client.get_replica_group_by_id | ( | self, | |
| group_id | |||
| ) |
Get the specified replica group of specified group id. Parameters: Name Type Info: group_id int The id of replica group. Return values: the replicagroup object of query. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.get_replica_group_by_name | ( | self, | |
| group_name | |||
| ) |
Get the specified replica group of specified group name. Parameters: Name Type Info: group_name str The name of replica group. Return values: the replicagroup object of query. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.get_session_attri | ( | self | ) |
Get the attributes of the session. Return values: a dict object of attributes Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.get_snapshot | ( | self, | |
| snap_type, | |||
| kwargs | |||
| ) |
Get the snapshots of specified type.
Parameters:
Name Type Info:
snap_type int The type of snapshot, see Info as below
**kwargs Useful options are below
- condition dict The matching rule, match all the documents
if not provided.
- selector dict The selective rule, return the whole
document if not provided.
- order_by dict The ordered rule, result set is unordered
if not provided.
Return values:
a cursor object of query
Exceptions:
pysequoiadb.error.SDBBaseError
Info:
snapshot type:
0 : Get all contexts' snapshot
1 : Get the current context's snapshot
2 : Get all sessions' snapshot
3 : Get the current session's snapshot
4 : Get the collections' snapshot
5 : Get the collection spaces' snapshot
6 : Get database's snapshot
7 : Get system's snapshot
8 : Get catalog's snapshot
9 : Get transactions' snapshot
10 : Get current session's transaction snapshot
| def pysequoiadb.client.client.is_domain_existing | ( | self, | |
| domain_name | |||
| ) |
Check the existence of specified domain.
Parameters:
Name Type Info
domain_name str The domain name.
Return values:
True if domain exists and False if not exists
Exceptions:
pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.is_valid | ( | self | ) |
Judge whether the connection is valid. Return values: bool Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.list_backup | ( | self, | |
| options, | |||
| kwargs | |||
| ) |
List the backups.
Parameters:
Name Type Info:
options dict Contains configuration information for backups,
list all the backups if the default backup path is None.
The "options" contains 3 options as below.
All the elements in options are optional.
eg:
{ "GroupName":["rgame1", "rgName2"],
"Path":"/opt/sequoiadb/backup",
"Name":"backupName" }
See Info as below.
**kwargs Useful option arw below
- condition dict The matching rule, return all the documents
if None.
- selector dict The selective rule, return the whole document
if None.
- order_by dict The ordered rule, never sort if None.
Return values:
a cursor object of backup list
Exceptions:
pysequoiadb.error.SDBBaseError
Info:
GroupName : Assign the backups of specified replica groups to be list.
Path : Assign the backups in specified path to be list,
if not assign, use the backup path assigned in the
configuration file.
Name : Assign the backups with specified name to be list.
| def pysequoiadb.client.client.list_collection_spaces | ( | self | ) |
List all collection space of current database, include temporary collection space. Return values: a cursor object of collection spaces. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.list_collections | ( | self | ) |
List all collections in current database. Return values: a cursor object of collection. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.list_domains | ( | self, | |
| kwargs | |||
| ) |
Get information of domains.
Parameters:
Name Type Info:
**kwargs Useful options are below
- condition dict The matching rule, match all the documents
if None.
- selector dict The selective rule, return the whole
documents if None.
- order_by dict The ordered rule, never sort if None.
Return values:
a cursor object of domains
Exceptions:
pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.list_procedures | ( | self, | |
| condition | |||
| ) |
List store procedures. Parameters: Name Type Info: condition dict The condition of list. Return values: an cursor object of result Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.list_replica_groups | ( | self | ) |
List all replica groups of current database. Return values: a cursor object of replication groups. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.list_tasks | ( | self, | |
| kwargs | |||
| ) |
List the tasks.
Parameters:
Name Type Info:
**kwargs Useful options are below
- condition dict The matching rule, return all the documents
if None.
- selector dict The selective rule, return the whole
document if None.
- order_by dict The ordered rule, never sort if None.
bson.SON may need if it is order-sensitive.
eg.
bson.SON([("name",-1), ("age":1)]) it will
be ordered descending by 'name' first, and
be ordered ascending by 'age'
- hint dict The hint, automatically match the optimal
hint if None.
Return values:
a cursor object of task list
Exceptions:
pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.remove_backup | ( | self, | |
| options | |||
| ) |
Remove the backups
Parameters:
Name Type Info:
options dict Contains configuration information for remove
backups, remove all the backups in the default
backup path if null. The "options" contains 3
options as below. All the elements in options are
optional.
eg:
{ "GroupName":["rgName1", "rgName2"],
"Path":"/opt/sequoiadb/backup",
"Name":"backupName" }
See Info as below.
Return values:
an cursor object of result
Exceptions:
pysequoiadb.error.SDBBaseError
Info:
GroupName : Assign the backups of specified replica groups to be
remove.
Path : Assign the backups in specified path to be remove, if not
assign, use the backup path assigned in the configuration
file.
Name : Assign the backups with specified name to be remove.
| def pysequoiadb.client.client.remove_cata_replica_group | ( | self | ) |
Remove the catalog replica group. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.remove_coord_replica_group | ( | self | ) |
Remove the coordinator replica group. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.remove_procedure | ( | self, | |
| name | |||
| ) |
Remove a store procedures. Parameters: Name Type Info: name str The name of store procedure. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.remove_replica_group | ( | self, | |
| group_name | |||
| ) |
Remove the specified replica group. Parameters: Name Type Info: group_name str The name of replica group to be removed Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.remove_user | ( | self, | |
| name, | |||
| psw | |||
| ) |
Remove the specified user from current database. Parameters: Name Type Info: name str The name of user to be removed. psw str The password of user to be removed. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.reset_snapshot | ( | self, | |
condition = None |
|||
| ) |
Reset the snapshot.
Parameters:
Name Type Info:
condition dict The control options are as below:(please visit the official website to search "Location Elements" for more detail.)
GroupID:INT32,
GroupName:String,
NodeID:INT32,
HostName:String,
svcname:String,
...
Exceptions:
pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.set_session_attri | ( | self, | |
| options | |||
| ) |
Set the attributes of the session.
Parameters:
Name Type Info:
options dict The configuration options for session. Could have "PreferedInstance", "PreferedInstanceMode" and "Timeout"
Exceptions:
pysequoiadb.error.SDBBaseError
Info:
PreferedInstance : Preferred instance for read request in the current session. Could be single value in "M", "m", "S", "s", "A", "a", 1-255, or BSON Array to include multiple values. e.g. { "PreferedInstance" : [ 1, 7 ] }.
"M", "m": read and write instance( master instance ). If multiple numeric instances are given with "M", matched master instance will be chosen in higher priority. If multiple numeric instances are given with "M" or "m", master instance will be chosen if no numeric instance is matched.
"S", "s": read only instance( slave instance ). If multiple numeric instances are given with "S", matched slave instances will be chosen in higher priority. If multiple numeric instances are given with "S" or "s", slave instance will be chosen if no numeric instance is matched.
"A", "a": any instance.
1-255: the instance with specified instance ID.
If multiple alphabet instances are given, only first one will be used.
If matched instance is not found, will choose instance by random.
PreferedInstanceMode : The mode to choose query instance when multiple preferred instances are found in the current session. e.g. { "PreferedInstanceMode : "random" }.
"random": choose the instance from matched instances by random.
"ordered": choose the instance from matched instances by the order of "PreferedInstance".
Timeout : The timeout (in ms) for operations in the current session. -1 means no timeout for operations. e.g. { "Timeout" : 10000 }.
| def pysequoiadb.client.client.start_replica_group | ( | self, | |
| group_name | |||
| ) |
Start the specified replica group. Parameters: Name Type Info: group_name str The name of replica group to be started Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.stop_replica_group | ( | self, | |
| group_name | |||
| ) |
Stop the specified replica group. Parameters: Name Type Info: group_name str The name of replica group to be stopped Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.transaction_begin | ( | self | ) |
Transaction begin. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.transaction_commit | ( | self | ) |
Transaction commit. Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.transaction_rollback | ( | self | ) |
Transaction rollback Exceptions: pysequoiadb.error.SDBBaseError
| def pysequoiadb.client.client.wait_task | ( | self, | |
| task_ids, | |||
| num | |||
| ) |
Wait the tasks to finish. Parameters: Name Type Info: task_ids list The list of task id. num int The number of task id. Exceptions: pysequoiadb.error.SDBBaseError
1.8.2