From 1387e6bfa1f16b87098e9d7f56e9513a91e74d7b Mon Sep 17 00:00:00 2001
From: Thong Kuah <tkuah@gitlab.com>
Date: Mon, 24 May 2021 13:34:40 +1200
Subject: [PATCH] Move LB Consistency to Core

---
 ee/lib/ee/gitlab/database/consistency.rb      | 20 -------------------
 lib/gitlab/database/consistency.rb            | 20 +++++--------------
 scripts/rspec_helpers.sh                      |  2 +-
 .../lib/gitlab/database/consistency_spec.rb   |  0
 4 files changed, 6 insertions(+), 36 deletions(-)
 delete mode 100644 ee/lib/ee/gitlab/database/consistency.rb
 rename {ee/spec => spec}/lib/gitlab/database/consistency_spec.rb (100%)

diff --git a/ee/lib/ee/gitlab/database/consistency.rb b/ee/lib/ee/gitlab/database/consistency.rb
deleted file mode 100644
index a3ccda7526f90..0000000000000
--- a/ee/lib/ee/gitlab/database/consistency.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-module EE
-  module Gitlab
-    module Database
-      module Consistency
-        extend ::Gitlab::Utils::Override
-        ##
-        # In EE we are disabling the database load balancing for calls that
-        # require read consistency after recent writes.
-        #
-        override :with_read_consistency
-        def with_read_consistency(&block)
-          ::Gitlab::Database::LoadBalancing::Session
-            .current.use_primary(&block)
-        end
-      end
-    end
-  end
-end
diff --git a/lib/gitlab/database/consistency.rb b/lib/gitlab/database/consistency.rb
index e99ea7a323275..17c16640e4c95 100644
--- a/lib/gitlab/database/consistency.rb
+++ b/lib/gitlab/database/consistency.rb
@@ -4,28 +4,18 @@ module Gitlab
   module Database
     ##
     # This class is used to make it possible to ensure read consistency in
-    # GitLab EE without the need of overriding a lot of methods / classes /
+    # GitLab without the need of overriding a lot of methods / classes /
     # classs.
     #
-    # This is a CE class that does nothing in CE, because database load
-    # balancing is EE-only feature, but you can still use it in CE. It will
-    # start ensuring read consistency once it is overridden in EE.
-    #
-    # Using this class in CE helps to avoid creeping discrepancy between CE /
-    # EE only to force usage of the primary database in EE.
-    #
     class Consistency
       ##
-      # In CE there is no database load balancing, so all reads are expected to
-      # be consistent by the ACID guarantees of a single PostgreSQL instance.
-      #
-      # This method is overridden in EE.
+      # Within the block, disable the database load balancing for calls that
+      # require read consistency after recent writes.
       #
       def self.with_read_consistency(&block)
-        yield
+        ::Gitlab::Database::LoadBalancing::Session
+          .current.use_primary(&block)
       end
     end
   end
 end
-
-::Gitlab::Database::Consistency.singleton_class.prepend_mod_with('Gitlab::Database::Consistency')
diff --git a/scripts/rspec_helpers.sh b/scripts/rspec_helpers.sh
index b1a618270b096..0484cabca82e0 100644
--- a/scripts/rspec_helpers.sh
+++ b/scripts/rspec_helpers.sh
@@ -85,7 +85,7 @@ function rspec_db_library_code() {
   local db_files="spec/lib/gitlab/database/ spec/support/helpers/database/"
 
   if [[ -d "ee/" ]]; then
-    db_files="${db_files} ee/spec/lib/gitlab/database/ ee/spec/lib/ee/gitlab/database_spec.rb"
+    db_files="${db_files} ee/spec/lib/ee/gitlab/database_spec.rb"
   fi
 
   rspec_simple_job "-- ${db_files}"
diff --git a/ee/spec/lib/gitlab/database/consistency_spec.rb b/spec/lib/gitlab/database/consistency_spec.rb
similarity index 100%
rename from ee/spec/lib/gitlab/database/consistency_spec.rb
rename to spec/lib/gitlab/database/consistency_spec.rb
-- 
GitLab