Browse Source

ref(nodestore): Hint to nodestore that we're in cleanup mode to skip doing deletes

This is a correct fix instead of
93a6971a8ef29c92bae802529bdf4f133dda3b2e
Matt Robenolt 6 years ago
parent
commit
e3c6f22805
2 changed files with 10 additions and 1 deletions
  1. 7 1
      src/sentry/nodestore/riak/backend.py
  2. 3 0
      src/sentry/runner/commands/cleanup.py

+ 7 - 1
src/sentry/nodestore/riak/backend.py

@@ -8,6 +8,7 @@ sentry.nodestore.riak.backend
 
 from __future__ import absolute_import
 
+import os
 import six
 
 from simplejson import JSONEncoder, _default_decoder
@@ -46,7 +47,8 @@ class RiakNodeStorage(NodeStorage):
         max_retries=3,
         multiget_pool_size=5,
         tcp_keepalive=True,
-        protocol=None
+        protocol=None,
+        automatic_expiry=False,
     ):
         # protocol being defined is useless, but is needed for backwards
         # compatability and leveraged as an opportunity to yell at the user
@@ -63,11 +65,15 @@ class RiakNodeStorage(NodeStorage):
             cooldown=cooldown,
             tcp_keepalive=tcp_keepalive,
         )
+        self.automatic_expiry = automatic_expiry
+        self.skip_deletes = automatic_expiry and '_SENTRY_CLEANUP' in os.environ
 
     def set(self, id, data):
         self.conn.put(self.bucket, id, json_dumps(data), returnbody='false')
 
     def delete(self, id):
+        if self.skip_deletes:
+            return
         self.conn.delete(self.bucket, id)
 
     def get(self, id):

+ 3 - 0
src/sentry/runner/commands/cleanup.py

@@ -7,6 +7,7 @@ sentry.runner.commands.cleanup
 """
 from __future__ import absolute_import, print_function
 
+import os
 from datetime import timedelta
 from uuid import uuid4
 
@@ -140,6 +141,8 @@ def cleanup(days, project, concurrency, silent, model, router, timed):
         click.echo('Error: Minimum concurrency is 1', err=True)
         raise click.Abort()
 
+    os.environ['_SENTRY_CLEANUP'] = '1'
+
     # Make sure we fork off multiprocessing pool
     # before we import or configure the app
     from multiprocessing import Process, JoinableQueue as Queue