简体   繁体   中英

AWS GLUE Pyspark job delete S3 folder unexpectly

My glue workflow is DDB -> GLUE table (by using Crawler) -> S3 (by using GLUE job)

I create S3 folder manually before the workflow run.

  1. For DDB table with size at 500~MB it always works fine (runs 7-10min to finish), the s3 path will have correct result: eg s3://glue_example/ddb_500MB/ (I know data is correct by checking them in athena after connecting to s3)

  2. For DDB table with size 50GB the folder is deleted by the GLUE JOB (runs 2 hours to finish, no error), eg s3://glue_example/ddb_50GB this folder is deleted. ( I enabled the log for s3, and in log, GlueJobRunnerSession used DeleteObject on this folder path )

  3. This delete folder behavior is not consistent, it happened most of the time, but if I find the folder is deleted, and I created manually, next run will have correct data in that s3 folder.

  4. The code of GLUE job (Glue 3.0 - Supports spark 3.1, Scala 2, Python 3) is super simple. the only line that write to s3 is : ApplyMapping_node2.toDF().write.mode("overwrite").format("parquet").save('s3://glue_example/ddb_50GB')

  5. concurrency of workflow/job is 1, so it's not competing caused problem

I use overwrite to keep the folder to have only latest data. but I don't know why this keep deleting folder with large size DDB as data source. Any idea?

The issue was due to whole table being read into single partition as it is default behaviour. Increasing dynamodb.splits while reading from DDB table should help as it reads data in parallel into multiple partitions.Below is an example in pySpark.

dyf = glue_context.create_dynamic_frame.from_options(
    connection_type="dynamodb",
    connection_options={"dynamodb.input.tableName": "test_source",
        "dynamodb.throughput.read.percent": "1.0",
        "dynamodb.splits": "100"
    }
)

Refer to below link for more information:

https://docs.aws.amazon.com/glue/latest/dg/aws-glue-programming-etl-connect.html#aws-glue-programming-etl-connect-dynamodb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM