Ver a proveniência

fix: don't use cache for sequence in mariadb (#17640)

* fix: don't use cache for sequence in mariadb

* chore: update sequence related comments
version-14
Ritwik Puri há 2 anos
committed by GitHub
ascendente
cometimento
cb6438158b
Não foi encontrada uma chave conhecida para esta assinatura, na base de dados ID da chave GPG: 4AEE18F83AFDEB23
4 ficheiros alterados com 18 adições e 16 eliminações
  1. +17
    -0
      frappe/database/database.py
  2. +0
    -9
      frappe/database/mariadb/database.py
  3. +1
    -1
      frappe/database/mariadb/schema.py
  4. +0
    -6
      frappe/database/postgres/database.py

+ 17
- 0
frappe/database/database.py Ver ficheiro

@@ -54,6 +54,23 @@ class Database:
CHILD_TABLE_COLUMNS = ("parent", "parenttype", "parentfield")
MAX_WRITES_PER_TRANSACTION = 200_000

# NOTE:
# FOR MARIADB - using no cache - as during backup, if the sequence was used in anyform,
# it drops the cache and uses the next non cached value in setval query and
# puts that in the backup file, which will start the counter
# from that value when inserting any new record in the doctype.
# By default the cache is 1000 which will mess up the sequence when
# using the system after a restore.
#
# Another case could be if the cached values expire then also there is a chance of
# the cache being skipped.
#
# FOR POSTGRES - The sequence cache for postgres is per connection.
# Since we're opening and closing connections for every request this results in skipping the cache
# to the next non-cached value hence not using cache in postgres.
# ref: https://stackoverflow.com/questions/21356375/postgres-9-0-4-sequence-skipping-numbers
SEQUENCE_CACHE = 0

class InvalidColumnName(frappe.ValidationError):
pass



+ 0
- 9
frappe/database/mariadb/database.py Ver ficheiro

@@ -129,15 +129,6 @@ class MariaDBConnectionUtil:

class MariaDBDatabase(MariaDBConnectionUtil, MariaDBExceptionUtil, Database):
REGEX_CHARACTER = "regexp"

# NOTE: using a very small cache - as during backup, if the sequence was used in anyform,
# it drops the cache and uses the next non cached value in setval query and
# puts that in the backup file, which will start the counter
# from that value when inserting any new record in the doctype.
# By default the cache is 1000 which will mess up the sequence when
# using the system after a restore.
# issue link: https://jira.mariadb.org/browse/MDEV-21786
SEQUENCE_CACHE = 50
CONVERSION_MAP = conversions | {
FIELD_TYPE.NEWDECIMAL: float,
FIELD_TYPE.DATETIME: get_datetime,


+ 1
- 1
frappe/database/mariadb/schema.py Ver ficheiro

@@ -44,7 +44,7 @@ class MariaDBTable(DBTable):

# NOTE: not used nextval func as default as the ability to restore
# database with sequences has bugs in mariadb and gives a scary error.
# issue link: https://jira.mariadb.org/browse/MDEV-21786
# issue link: https://jira.mariadb.org/browse/MDEV-20070
name_column = "name bigint primary key"

# create table


+ 0
- 6
frappe/database/postgres/database.py Ver ficheiro

@@ -102,12 +102,6 @@ class PostgresExceptionUtil:

class PostgresDatabase(PostgresExceptionUtil, Database):
REGEX_CHARACTER = "~"

# NOTE; The sequence cache for postgres is per connection.
# Since we're opening and closing connections for every transaction this results in skipping the cache
# to the next non-cached value hence not using cache in postgres.
# ref: https://stackoverflow.com/questions/21356375/postgres-9-0-4-sequence-skipping-numbers
SEQUENCE_CACHE = 0
default_port = "5432"

def setup_type_map(self):


Carregando…
Cancelar
Guardar