[ad_1]
Introduction
For greater than a decade now, the Hive desk format has been a ubiquitous presence within the massive knowledge ecosystem, managing petabytes of information with outstanding effectivity and scale. However as the info volumes, knowledge selection, and knowledge utilization grows, customers face many challenges when utilizing Hive tables due to its antiquated directory-based desk format. A few of the widespread points embody constrained schema evolution, static partitioning of information, and lengthy planning time due to S3 listing listings.
Apache Iceberg is a contemporary desk format that not solely addresses these issues but in addition provides further options like time journey, partition evolution, desk versioning, schema evolution, robust consistency ensures, object retailer file structure (the flexibility to distribute recordsdata current in a single logical partition throughout many prefixes to keep away from object retailer throttling), hidden partitioning (customers don’t must be intimately conscious of partitioning), and extra. Due to this fact, Apache Iceberg desk format is poised to interchange the standard Hive desk format within the coming years.
Nonetheless, as there are already 25 million terabytes of information saved within the Hive desk format, migrating current tables within the Hive desk format into the Iceberg desk format is critical for efficiency and price. Relying on the dimensions and utilization patterns of the info, a number of completely different methods might be pursued to realize a profitable migration. On this weblog, I’ll describe a number of methods one might undertake for varied use circumstances. Whereas these directions are carried out for Cloudera Knowledge Platform (CDP), Cloudera Knowledge Engineering, and Cloudera Knowledge Warehouse, one can extrapolate them simply to different providers and different use circumstances as properly.
There are few eventualities that one would possibly encounter. A number of of those use circumstances would possibly suit your workload and also you would possibly be capable of combine and match the potential options offered to fit your wants. They’re meant to be a normal information. In all of the use circumstances we are attempting emigrate a desk named “occasions.”
Strategy 1
You will have the flexibility to cease your shoppers from writing to the respective Hive desk throughout the length of your migration. That is superb as a result of this would possibly imply that you simply don’t have to change any of your consumer code. Generally that is the one alternative obtainable you probably have a whole lot of shoppers that may probably write to a desk. It might be a lot simpler to easily cease all these jobs fairly than permitting them to proceed throughout the migration course of.
In-place desk migration
Resolution 1A: utilizing Spark’s migrate process
Iceberg’s Spark extensions present an in-built process known as “migrate” emigrate an current desk from Hive desk format to Iceberg desk format. In addition they present a “snapshot” process that creates an Iceberg desk with a unique identify with the identical underlying knowledge. You may first create a snapshot desk, run sanity checks on the snapshot desk, and be certain that every little thing is so as.
As soon as you might be happy you may drop the snapshot desk and proceed with the migration utilizing the migrate process. Take into account that the migrate process creates a backup desk named “events__BACKUP__.” As of this writing, the “__BACKUP__” suffix is hardcoded. There may be an effort underway to let the consumer go a customized backup suffix sooner or later.
Take into account that each the migrate and snapshot procedures don’t modify the underlying knowledge: they carry out in-place migration. They merely learn the underlying knowledge (not even full learn, they only learn the parquet headers) and create corresponding Iceberg metadata recordsdata. Because the underlying knowledge recordsdata will not be modified, you could not be capable of take full benefit of the advantages supplied by Iceberg instantly. You may optimize your desk now or at a later stage utilizing the “rewrite_data_files” process. This will likely be mentioned in a later weblog. Now let’s talk about the professionals and cons of this strategy.
PROS:
- Can do migration in phases: first do the migration after which perform the optimization later utilizing rewrite_data_files process (weblog to observe).
- Comparatively quick because the underlying knowledge recordsdata are saved in place. You don’t have to fret about creating a brief desk and swapping it later. The process will do this for you atomically as soon as the migration is completed.
- Since a Hive backup is obtainable one can revert the change completely by dropping the newly created Iceberg desk and by renaming the Hive backup desk (__backup__) desk to its authentic identify.
CONS:
- If the underlying knowledge is just not optimized, or has loads of small recordsdata, these disadvantages might be carried ahead to the Iceberg desk as properly. Question engines (Impala, Hive, Spark) would possibly mitigate a few of these issues by utilizing Iceberg’s metadata recordsdata. The underlying knowledge file places is not going to change. So if the prefixes of the file path are widespread throughout a number of recordsdata we might proceed to endure from S3 throttling (see Object Retailer File Layout to see methods to configure it correctly.) In CDP we solely assist migrating exterior tables. Hive managed tables can’t be migrated. Additionally, the underlying file format for the desk must be certainly one of avro, orc, or parquet.
Observe: There may be additionally a SparkAction within the JAVA API.
Resolution 1B: utilizing Hive’s “ALTER TABLE” command
Cloudera applied a straightforward technique to do the migration in Hive. All it’s a must to do is to change the desk properties to set the storage handler to “HiveIcebergStorageHandler.”
The professionals and cons of this strategy are primarily the identical as Resolution 1B. The migration is finished in place and the underlying knowledge recordsdata will not be modified. Hive creates Iceberg’s metadata recordsdata for a similar actual desk.
Shadow desk migration
Resolution 1C: utilizing the CTAS assertion
This resolution is most generic and it might probably be used with any processing engine (Spark/Hive/Impala) that helps SQL-like syntax.
You’ll be able to run primary sanity checks on the info to see if the newly created desk is sound.
As soon as you might be happy along with your sanity checking you might rename your “occasions” desk to a “backup_events” desk after which rename your “iceberg_events” to “occasions.” Take into account that in some circumstances the rename operation would possibly set off a listing rename of the underlying knowledge listing. If that’s the case and your underlying knowledge retailer is an object retailer like S3, that may set off a full copy of your knowledge and might be very costly. If whereas creating the Iceberg desk the placement clause is specified, then the renaming operation of the Iceberg desk is not going to trigger the underlying knowledge recordsdata to maneuver. The identify will change solely within the Hive metastore. The identical applies for Hive tables as properly. In case your authentic Hive desk was not created with the placement clause specified, then the rename to backup will set off a listing rename. In that case, In case your filesystem is object retailer based mostly, then it may be greatest to drop it altogether. Given the nuances round desk rename it’s essential to check with dummy tables in your system and examine that you’re seeing your required habits earlier than you carry out these operations on essential tables.
You’ll be able to drop your “backup_events” if you want.
Your shoppers can now resume their learn/write operations on the “occasions” and so they don’t even must know that the underlying desk format has modified. Now let’s talk about the professionals and cons of this strategy.
PROS:
- The newly created knowledge is properly optimized for Iceberg and the info will likely be distributed properly.
- Any current small recordsdata will likely be coalesced routinely.
- Frequent process throughout all of the engines.
- The newly created knowledge recordsdata might reap the benefits of Iceberg’s Object Retailer File Format, in order that the file paths have completely different prefixes, thus lowering object retailer throttling. Please see the linked documentation to see methods to reap the benefits of this function.
- This strategy is just not essentially restricted to migrating a Hive desk. One might use the identical strategy emigrate tables obtainable in any processing engine like Delta, Hudi, and so on.
- You’ll be able to change the info format say from “orc” to “parquet.’’
CONS
- This may set off a full learn and write of the info and it may be an costly operation.
- Your whole knowledge set will likely be duplicated. It’s essential have ample cupboard space obtainable. This shouldn’t be an issue in a public cloud backed by an object retailer.
Strategy 2
You don’t have the luxurious of lengthy downtime to do your migration. You wish to let your shoppers or jobs proceed writing the info to the desk. This requires some planning and testing, however is feasible with some caveats. Right here is a method you are able to do it with Spark. You’ll be able to probably extrapolate the concepts introduced to different engines.
- Create an Iceberg desk with the specified properties. Take into account that it’s a must to maintain the partitioning scheme the identical for this to work accurately.
- Modify your shoppers or jobs to write down to each tables in order that they write to the “iceberg_events” desk and “occasions” desk. However for now, they solely learn from the “occasions” desk. Seize the timestamp from which your shoppers began writing to each of the tables.
- You programmatically listing all of the recordsdata within the Hive desk that have been inserted earlier than the timestamp you captured in step 2.
- Add all of the recordsdata captured in step 3 to the Iceberg desk utilizing the “add_files” process. The “add_files” process will merely add the file to your Iceberg desk. You additionally would possibly be capable of reap the benefits of your desk’s partitioning scheme to skip step 3 completely and add recordsdata to your newly created Iceberg desk utilizing the “add_files” process.
- In the event you don’t have entry to Spark you would possibly merely learn every of the recordsdata listed in step 3 and insert them into the “iceberg_events.”
- When you efficiently add all the info recordsdata, you may cease your shoppers from studying/writing to the outdated “occasions” and use the brand new “iceberg_events.”
Some caveats and notes
- In step 2, you may management which tables your shoppers/jobs must write to utilizing some flag that may be fetched from exterior sources like setting variables, some database (like Redis) pointer, and properties recordsdata, and so on. That method you solely have to change your consumer/job code as soon as and don’t must maintain modifying it for every step.
- In step 2, you might be capturing a timestamp that will likely be used to calculate recordsdata wanted for step 3; this might be affected by clock drift in your nodes. So that you would possibly wish to sync all of your nodes earlier than you begin the migration course of.
- In case your desk is partitioned by date and time (as most actual world knowledge is partitioned), as in all new knowledge coming will go to a brand new partition on a regular basis, then you definitely would possibly program your shoppers to begin writing to each the tables from a particular date and time. That method you simply have to fret about including the info from the outdated desk (“occasions”) to the brand new desk (“Iceberg_events”) from that date and time, and you’ll reap the benefits of your partitioning scheme and skip step 3 completely. That is the strategy that ought to be used each time potential.
Conclusion
Any giant migration is hard and must be thought by rigorously. Fortunately, as mentioned above there are a number of methods at our disposal to do it successfully relying in your use case. You probably have the flexibility to cease all of your jobs whereas the migration is going on it’s comparatively simple, however if you wish to migrate with minimal to no downtime then that requires some planning and cautious considering by your knowledge structure. You need to use a mix of the above approaches to greatest fit your wants.
To be taught extra:
- For extra on desk migration, please consult with respective on-line documentations in Cloudera Knowledge Warehouse (CDW) and Cloudera Knowledge Engineering (CDE).
- Watch our webinar Supercharge Your Analytics with Open Knowledge Lakehouse Powered by Apache Iceberg. It features a reside demo recording of Iceberg capabilities.
- Strive Cloudera Knowledge Warehouse (CDW), Cloudera Knowledge Engineering (CDE), and Cloudera Machine Studying (CML) by signing up for a 60 day trial, or take a look at drive CDP. You can too schedule a demo by clicking right here or if you have an interest in chatting about Apache Iceberg in CDP, contact your account crew.
[ad_2]