@@ -61,6 +61,39 @@ local function peer_uris(configdata)
61
61
return uris
62
62
end
63
63
64
+ -- Modify box-level configuration values and perform other actions
65
+ -- to enable the isolated mode (if configured).
66
+ local function switch_isolated_mode (configdata , box_cfg )
67
+ -- If the isolated mode is not enabled, there is nothing to do.
68
+ if not configdata :get (' isolated' , {use_default = true }) then
69
+ return
70
+ end
71
+
72
+ -- An application or a role may perform background database
73
+ -- modification if the instance is in the RW mode: for
74
+ -- example, a role may perform eviction of stale records.
75
+ -- If the instance is in the isolated mode, it should be in RO
76
+ -- to don't produce any new transactions.
77
+ --
78
+ -- The reason is that these transactions will be sent to other
79
+ -- replicaset members and applied on them, when the instance
80
+ -- goes from the isolated mode. At the same time, the
81
+ -- non-isolated part of the replicaset may serve requests and
82
+ -- perform data modifications. An attempt to modify the same
83
+ -- data from two instances may break data integrity[^1].
84
+ --
85
+ -- It is recommended to extract all the needed data from the
86
+ -- isolated instance and perform the modifications on the
87
+ -- current leader (in the non-isolated part of the
88
+ -- replicaset).
89
+ --
90
+ -- [^1]: Unless the data operations are carefully designed to
91
+ -- be idempotent to use in the master-master mode.
92
+ --
93
+ -- TODO(gh-10404): Set ro_reason=isolated.
94
+ box_cfg .read_only = true
95
+ end
96
+
64
97
local function log_destination (log )
65
98
if log .to == ' stderr' or log .to == ' devnull' then
66
99
return box .NULL
@@ -644,6 +677,10 @@ local function apply(config)
644
677
labels = labels or { alias = names .instance_name },
645
678
}
646
679
680
+ -- RO may be enforced by the isolated mode, so we call the
681
+ -- function after all the other logic that may set RW.
682
+ switch_isolated_mode (configdata , box_cfg )
683
+
647
684
-- First box.cfg() call.
648
685
--
649
686
-- Force the read-only mode if:
@@ -653,6 +690,10 @@ local function apply(config)
653
690
-- * there is an existing snapshot (otherwise we wouldn't able
654
691
-- to assign a bootstrap leader).
655
692
--
693
+ -- NB: The read-only mode may be enforced due to other reasons
694
+ -- (such as enabled isolated mode) that are not specific to
695
+ -- the startup flow.
696
+ --
656
697
-- The reason is that the configured master may be switched
657
698
-- while it is starting. In this case it is undesirable to set
658
699
-- RW mode if the actual configuration marks the instance as
0 commit comments