You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'''The following script will simulate Truncate table in a region for the Amazon Keyspaces service.
2
+
This is achieved by dropping the existing table by executing the DROP command. The DROP command itself is asynchronous and success is only a service side
3
+
confirmation of the request, but not confirmation that resources have been removed. When the table no longer appears
4
+
in the system.schema_mcs table is it considered fully removed. Once the table is dropped script will recreate table with existing custom properties. The CREATE command itself is asynchronous and success is only a service side
5
+
confirmation of the request, but not confirmation that resources have been Creates. When the table Status appears as 'ACTIVE' in the system.schema_mcs table is considered ready for Usage. Prior to table being dropped and recreated the schema of the table is backed to ~/.cassandra/truncate log
6
+
7
+
Currently the script will wait for 15 + 15 mins for table deletion/ creation to be complete, In case of exceptions or duration excedeed script will fail
8
+
9
+
Usage - The inputs for the script are keyspace name, table name , and region respectively , for private endpoints need to manually change the endpoint variable in the script
10
+
11
+
## Prerequisites cqlsh-expansion (download required libraries for script execution like cassandra-driver, sigv4 etc)
12
+
To install Refer to https://pypi.org/project/cqlsh-expansion/
parser.add_option("--sigv4", action='store_true', help='Use SigV4AuthProvider plugin for autentication and authorization', default=DEFAULT_SIGV4)
47
+
parser.add_option("--auth-provider", help="The AuthProvider to use when connecting. Default is PlainTextAuthProvider", dest='auth_provider_name', default=DEFAULT_AUTH_PROVIDER)
48
+
parser.add_option("-u", "--username", help="Authenticate as user.")
49
+
parser.add_option("-p", "--password", help="Authenticate using password.")
# Removes the unicode(u) after converting to string
173
+
defunicode_fixer(obj):
174
+
returnstr(obj).replace("u'", "'")
175
+
176
+
# Retrieves the properties of the table such as TTL, Comments, Provisioning, Encryption
177
+
cust_set=session.execute(("select custom_properties from system_schema_mcs.tables WHERE keyspace_name = %s AND table_name = %s"), (ks,tb)).one()
178
+
prop_set=session.execute(("select comment, default_time_to_live from system_schema_mcs.tables WHERE keyspace_name = %s AND table_name = %s"), (ks,tb)).one()
179
+
180
+
ifprop_set['comment']:
181
+
ttl_comm=' default_time_to_live = '+unicode_fixer(prop_set['default_time_to_live']) +' AND comment = '+'\''+unicode_fixer(prop_set['comment']) +'\''
tags_result_set=session.execute(("SELECT * FROM system_schema_mcs.tags WHERE keyspace_name = %s AND resource_name = %s "), (ks,tb))
196
+
tags_data=tags_result_set.one()
197
+
tags_sch=unicode_fixer(tags_data['tags'])
198
+
199
+
# Building the schema to recreate the table
200
+
final_schema=recreate_table+ttl_comm+' AND TAGS = '+tags_sch+' AND CUSTOM_PROPERTIES = '+cust_prop
201
+
202
+
# Printing final schema to log as backup for scenarios when table was dropped and unable to recreate succesfully
203
+
logger.info(final_schema)
204
+
205
+
# execute the command check the status of the table. If no exception this represents acknowledgement that the service has received the request.
206
+
defDDL_status(resultset):
207
+
try:
208
+
results=resultset.result()
209
+
status=session.execute(('SELECT keyspace_name, table_name, status FROM system_schema_mcs.tables WHERE keyspace_name = %s AND table_name = %s'), (ks,tb))
0 commit comments