Class: Code0::ZeroTrack::Database::Partitioning::PartitionManager
- Inherits:
-
Object
- Object
- Code0::ZeroTrack::Database::Partitioning::PartitionManager
- Includes:
- Loggable
- Defined in:
- lib/code0/zero_track/database/partitioning/partition_manager.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Class Method Summary collapse
Instance Method Summary collapse
- #create_partitions! ⇒ Object
- #detach_partitions! ⇒ Object
- #drop_partitions! ⇒ Object
-
#initialize(model) ⇒ PartitionManager
constructor
A new instance of PartitionManager.
- #sync_partitions! ⇒ Object
Methods included from Loggable
Constructor Details
#initialize(model) ⇒ PartitionManager
Returns a new instance of PartitionManager.
37 38 39 40 41 42 43 |
# File 'lib/code0/zero_track/database/partitioning/partition_manager.rb', line 37 def initialize(model) if model.try(:partitioning_strategy).nil? raise ArgumentError, "Model #{model} not configured for partitioning" end @model = model end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
35 36 37 |
# File 'lib/code0/zero_track/database/partitioning/partition_manager.rb', line 35 def model @model end |
Class Method Details
.register_model(clazz) ⇒ Object
15 16 17 |
# File 'lib/code0/zero_track/database/partitioning/partition_manager.rb', line 15 def self.register_model(clazz) models << clazz end |
.reset_registered_models! ⇒ Object
19 20 21 |
# File 'lib/code0/zero_track/database/partitioning/partition_manager.rb', line 19 def self.reset_registered_models! models.clear end |
.sync_all_partitions! ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/code0/zero_track/database/partitioning/partition_manager.rb', line 23 def self.sync_all_partitions! models.each do |model| new(model).create_partitions! end models.reverse_each do |model| manager = new(model) manager.detach_partitions! manager.drop_partitions! end end |
Instance Method Details
#create_partitions! ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/code0/zero_track/database/partitioning/partition_manager.rb', line 53 def create_partitions! with_lock do |connection| model.partitioning_strategy.partitions_to_create.each do |partition| create_partition(partition, connection) attach_partition(partition, connection) end end end |
#detach_partitions! ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/code0/zero_track/database/partitioning/partition_manager.rb', line 62 def detach_partitions! with_lock do |connection| model.partitioning_strategy.partitions_to_detach.each do |partition| detach_partition(partition, connection) end end end |
#drop_partitions! ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/code0/zero_track/database/partitioning/partition_manager.rb', line 70 def drop_partitions! with_lock do |connection| model.partitioning_strategy.partitions_to_drop.each do |detached_partition| drop_partition(detached_partition, connection) end end end |
#sync_partitions! ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/code0/zero_track/database/partitioning/partition_manager.rb', line 45 def sync_partitions! create_partitions! detach_partitions! drop_partitions! end |