-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle in-flight exits deletions
- Loading branch information
Showing
19 changed files
with
406 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
apps/omg_db/lib/omg_db/release_tasks/init_keys_with_values.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright 2019-2019 OmiseGO Pte Ltd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
defmodule OMG.DB.ReleaseTasks.InitKeysWithValues do | ||
@moduledoc """ | ||
Sets values for keys stored in RocksDB, if they are not set. | ||
""" | ||
require Logger | ||
|
||
@keys_to_values [last_ife_exit_deleted_eth_height: 0] | ||
|
||
def run() do | ||
{:ok, _} = Application.ensure_all_started(:logger) | ||
|
||
path = Application.get_env(:omg_db, :path) | ||
Application.put_env(:omg_db, :path, path) | ||
|
||
case Application.ensure_all_started(:omg_db) do | ||
{:ok, _} -> | ||
Enum.each(@keys_to_values, &set_single_value/1) | ||
|
||
{:error, _} -> | ||
_ = Logger.info("DB not initialized yet, no action required") | ||
:ok | ||
end | ||
end | ||
|
||
defp set_single_value({key, init_val}) do | ||
case OMG.DB.RocksDB.get_single_value(key) do | ||
:not_found -> | ||
:ok = OMG.DB.RocksDB.multi_update([{:put, key, init_val}]) | ||
_ = Logger.info("#{key} not set. Setting it to #{inspect(init_val)}") | ||
:ok | ||
|
||
{:ok, _} -> | ||
:ok | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
apps/omg_db/test/omg_db/release_tasks/init_keys_with_values_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2019-2020 OmiseGO Pte Ltd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
defmodule OMG.DB.ReleaseTasks.InitKeysWithValuesTest do | ||
use ExUnit.Case, async: false | ||
alias OMG.DB.ReleaseTasks.InitKeysWithValues | ||
alias OMG.DB.RocksDB | ||
alias OMG.DB.RocksDB.Server | ||
|
||
setup do | ||
{:ok, dir} = Briefly.create(directory: true) | ||
:ok = Server.init_storage(dir) | ||
:ok = Application.put_env(:omg_db, :path, dir, persistent: true) | ||
{:ok, started_apps} = Application.ensure_all_started(:omg_db) | ||
|
||
on_exit(fn -> | ||
:ok = Application.put_env(:omg_db, :path, nil) | ||
Enum.map(started_apps, fn app -> _ = Application.stop(app) end) | ||
end) | ||
|
||
{:ok, %{}} | ||
end | ||
|
||
test ":last_ife_exit_deleted_eth_height is set if it wasn't set previously" do | ||
:ok = RocksDB.multi_update([{:delete, :last_ife_exit_deleted_eth_height, 0}]) | ||
|
||
assert InitKeysWithValues.run() == :ok | ||
assert RocksDB.get_single_value(:last_ife_exit_deleted_eth_height) == {:ok, 0} | ||
end | ||
|
||
test "value under :last_ife_exit_deleted_eth_height is not changed if it was already set" do | ||
initial_value = 5 | ||
:ok = RocksDB.multi_update([{:put, :last_ife_exit_deleted_eth_height, initial_value}]) | ||
|
||
assert InitKeysWithValues.run() == :ok | ||
assert RocksDB.get_single_value(:last_ife_exit_deleted_eth_height) == {:ok, initial_value} | ||
end | ||
|
||
test "does not fail when omg db is not started" do | ||
:ok = Application.stop(:omg_db) | ||
:ok = Application.put_env(:omg_db, :path, nil) | ||
|
||
assert InitKeysWithValues.run() == :ok | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.