Class: ThreeScale::Backend::Stats::Cleaner
- Inherits:
-
Object
- Object
- ThreeScale::Backend::Stats::Cleaner
- Extended by:
- Logging
- Includes:
- ThreeScale::Backend::Storable
- Defined in:
- lib/3scale/backend/stats/cleaner.rb
Class Method Summary collapse
-
.delete!(redis_conns, log_deleted_keys: nil) ⇒ Object
Deletes all the stats for the services that have been marked for deletion.
-
.delete_stats_keys_set_to_0(redis_conns, log_deleted_keys: nil) ⇒ Object
Deletes all the stats keys set to 0.
- .mark_service_to_be_deleted(service_id) ⇒ Object
Methods included from Logging
Methods included from ThreeScale::Backend::Storable
included, #initialize, #storage
Methods included from ThreeScale::Backend::StorageKeyHelpers
Class Method Details
.delete!(redis_conns, log_deleted_keys: nil) ⇒ Object
Deletes all the stats for the services that have been marked for deletion.
This method receives a collection of instantiated Redis clients. Those clients need to connect to Redis servers directly. They cannot connect to a proxy like Twemproxy. The reason is that this function needs to scan the database using the “SCAN” command, which is not supported by Twemproxy.
The services marked as deletion will be marked as done only when this function finishes deleting the keys from all the Redis servers. This means that if the function raises in the middle of the execution, those services will be retried in the next call.
Note 1: keys deleted cannot be restored. Note 2: this method can take a long time to finish as it needs to scan all the keys in several DBs.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/3scale/backend/stats/cleaner.rb', line 75 def delete!(redis_conns, log_deleted_keys: nil) services = services_to_delete logger.info("Going to delete the stats keys for these services: #{services.to_a}") unless services.empty? _ok, failed = redis_conns.partition do |redis_conn| begin delete_keys(redis_conn, services, log_deleted_keys) true rescue => e handle_redis_exception(e, redis_conn) false end end with_retries { remove_services_from_delete_set(services) } if failed.empty? failed.each do |failed_conn| logger.error("Error while deleting stats of server #{failed_conn}") end end logger.info("Finished deleting the stats keys for these services: #{services.to_a}") end |
.delete_stats_keys_set_to_0(redis_conns, log_deleted_keys: nil) ⇒ Object
Deletes all the stats keys set to 0.
Stats keys set to 0 are useless and occupy Redis memory unnecessarily. They were generated due to a bug in previous versions of Apisonator. Ref: github.com/3scale/apisonator/pull/247
As the .delete function, this one also receives a collection of instantiated Redis clients and those need to connect to Redis servers directly.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/3scale/backend/stats/cleaner.rb', line 114 def delete_stats_keys_set_to_0(redis_conns, log_deleted_keys: nil) _ok, failed = redis_conns.partition do |redis_conn| begin delete_stats_keys_with_val_0(redis_conn, log_deleted_keys) true rescue => e handle_redis_exception(e, redis_conn) false end end failed.each do |failed_conn| logger.error("Error while deleting stats of server #{failed_conn}") end end |
.mark_service_to_be_deleted(service_id) ⇒ Object
50 51 52 |
# File 'lib/3scale/backend/stats/cleaner.rb', line 50 def mark_service_to_be_deleted(service_id) storage.sadd(KEY_SERVICES_TO_DELETE, service_id) end |