forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mysql change xcom value col type for MySQL backend (apache#38401)
* Change table Xcom value column value type to longblob from blob Xcom value we can store Airflow metadata is a bit smaller when we use MySQL as a database backend since by default, the Sqlalchemy map LargeBinary to MySQL blob type which can store up to 65,535 bytes. In this PR, I'm proposing to change the value column type to longblob for xcom table if a user using MySQL database backend https://dev.mysql.com/doc/refman/8.0/en/string-type-syntax.html
- Loading branch information
1 parent
b2a976b
commit 6bca782
Showing
4 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
airflow/migrations/versions/0138_2_9_0_make_xcom_value_to_longblob_for_mysql.py
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,52 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you 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. | ||
|
||
"""Change value column type to longblob in xcom table for mysql | ||
Revision ID: b4078ac230a1 | ||
Revises: 8e1c784a4fc7 | ||
Create Date: 2024-03-22 14:06:51.185268 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects.mysql import LONGBLOB | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'b4078ac230a1' | ||
down_revision = '8e1c784a4fc7' | ||
branch_labels = None | ||
depends_on = None | ||
airflow_version = '2.9.0' | ||
|
||
|
||
def upgrade(): | ||
"""Apply Change value column type to longblob in xcom table for mysql""" | ||
conn = op.get_bind() | ||
if conn.dialect.name == "mysql": | ||
with op.batch_alter_table("xcom", schema=None) as batch_op: | ||
batch_op.alter_column("value", type_=sa.LargeBinary().with_variant(LONGBLOB, "mysql")) | ||
|
||
|
||
def downgrade(): | ||
"""Unapply Change value column type to longblob in xcom table for mysql""" | ||
conn = op.get_bind() | ||
if conn.dialect.name == "mysql": | ||
with op.batch_alter_table("xcom", schema=None) as batch_op: | ||
batch_op.alter_column("value", type_=sa.LargeBinary) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -961,6 +961,7 @@ logformat | |
loglevel | ||
Logstash | ||
logstash | ||
longblob | ||
Lowin | ||
lshift | ||
lxml | ||
|
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,5 @@ | ||
Change xcom table column value type to longblob for MySQL backend. | ||
|
||
Xcom table column ``value`` type has changed from ``blob`` to ``longblob``. This will allow you to store relatively big data in Xcom but process can take a significant amount of time if you have a lot of large data stored in Xcom. | ||
|
||
To downgrade from revision: ``b4078ac230a1``, ensure that you don't have Xcom values larger than 65,535 bytes. Otherwise, you'll need to clean those rows or run ``airflow db clean xcom`` to clean the Xcom table. |