Beberapa waktu lalu, platform Apache Ignite muncul di cakrawala dan mulai mendapatkan popularitas. Komputasi dalam memori adalah kecepatan, yang berarti kecepatan harus dipastikan di semua tahap pekerjaan, terutama saat memuat data.
Di bawah potongan adalah deskripsi cara cepat memuat data dari tabel relasional ke cluster Apache Ignite terdistribusi. Pemrosesan awal dari hasil kueri SQL yang ditetapkan pada node klien cluster dan distribusi data di seluruh cluster menggunakan tugas pengurangan peta dijelaskan. Menjelaskan cache dan tabel relasional terkait, menunjukkan cara membuat objek kustom dari baris tabel, dan cara menggunakan ComputeTaskAdapter untuk menempatkan objek yang dibuat dengan cepat. Semua kode dapat dilihat secara lengkap di repositori FastDataLoad .
Sejarah masalah
Teks ini adalah terjemahan dari posting saya ke dalam bahasa Rusia di Blog In-Memory Computing di situs GridGain.
Jadi, perusahaan tertentu memutuskan untuk mempercepat aplikasi yang lambat dengan memindahkan komputasi ke cluster dalam memori. Data awal untuk kalkulasi ada di MS SQL; hasil perhitungan harus ditaruh disana. Cluster didistribusikan, karena sudah ada banyak data sekarang, kinerja aplikasi berada pada batas dan volume data bertambah. Batas waktu sulit ditetapkan.
Sebelum menulis kode cepat untuk memproses data, data perlu dimuat dengan cepat. Pencarian panik di web mengungkapkan kurangnya contoh kode yang dapat diskalakan ke tabel yang terdiri dari puluhan atau ratusan juta baris. Contoh yang dapat Anda unduh, kompilasi, dan ikuti langkah-langkah dalam debugging. Ini di satu sisi.
, Apache Ignite / GridGain, . , . " ?", — , .
, .
(World Database)
, data collocation, . world.sql Apache Ignite.
CSV , — SQL :
- countryCache — country.csv;
- cityCache — city.csv;
- countryLanguageCache — countryLanguage.csv.
countryCache country.csv. countryCache — code, — String, — Country, (name, continent, region).

, — , . Country , . org.h2.tools.Csv, CSV java.sql.ResultSet. Apache Ignite , SQL H2.
// define countryCache
IgniteCache<String,Country> cache = ignite.cache("countryCache");
try (ResultSet rs = new Csv().read(csvFileName, null, null)) {
while (rs.next()) {
String code = rs.getString("Code");
String name = rs.getString("Name");
String continent = rs.getString("Continent");
Country country = new Country(code,name,continent);
cache.put(code,country);
}
}
. , , . - .
, . , .
Apache Ignite — -. , PARTITIONED - (partition) . ; , . -, affinity function, , .

, :
- HashMap partition_number -> key -> Value
Map<Integer, Map<String, Country>> result = new HashMap<>(); - affinity function partition_number. cache.put() - HashMap partition_number
try (ResultSet rs = new Csv().read(csvFileName, null, null)) { while (rs.next()) { String code = rs.getString("Code"); String name = rs.getString("Name"); String continent = rs.getString("Continent"); Country country = new Country(code,name,continent); result.computeIfAbsent(affinity.partition(key), k -> new HashMap<>()).put(code,country); } }
ComputeTaskAdapter ComputeJobAdapter. ComputeJobAdapter 1024. , .
ComputeJobAdapter . , .
Compute Task,
, "ComputeTaskAdapter initiates the simplified, in-memory, map-reduce process". ComputeJobAdapter map — , . reduce — .
(RenewLocalCacheJob)
targetCache.putAll(addend);
RenewLocalCacheJob partition_number .
(AbstractLoadTask)
( loader) — AbstractLoadTask. . ( ), AbstractLoadTask TargetCacheKeyType. HashMap
Map<Integer, Map<TargetCacheKeyType, BinaryObject>> result;
countryCache String. . AbstractLoadTask TargetCacheKeyType, BinaryObject. , — .
BinaryObject
— . , JVM, - . class definition , JAR- . Country
IgniteCache<String, Country> countryCache;
, , classpath ClassNotFound.
. — classpath, :
- JAR- ;
- classpath ;
- ;
- .
— BinaryObject () . :
-
IgniteCache<String, BinaryObject> countryCache; - Country BinaryObject (. LoadCountries.java)
Country country = new Country(code, name, .. ); BinaryObject binCountry = node.binary().toBinary(country); - HashMap, BinaryObject
Map<Integer, Map<String, BinaryObject>> result
, . , , ClassNotFoundException .
. .
Apache Ignite : .
default-config.xml — . :
- GridGain CE Installing Using ZIP Archive. 8.7.10, FastDataLoad , ;
- {gridgain}\config default-config.xml
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"> <property name="peerClassLoadingEnabled" value="true"/> </bean> - , {gridgain}\bin ignite.bat. ; ;
- , . ,
[08:40:04] Topology snapshot [ver=2, locNode=d52b1db3, servers=2, clients=0, state=ACTIVE, CPUs=8, offheap=3.2GB, heap=2.0GB]
. , 8.7.25, pom.xml
<gridgain.version>8.7.25</gridgain.version>
class org.apache.ignite.spi.IgniteSpiException: Local node and remote node have different version numbers (node will not join, Ignite does not support rolling updates, so versions must be exactly the same) [locBuildVer=8.7.25, rmtBuildVer=8.7.10]
, , map-reduce. — JAR-, compute task . Windows, Linux.
:
- FastDataLoad;
- ;
mvn clean package - , .
java -jar .\target\fastDataLoad.jar
main() LoadApp LoaderAgrument . map-reduce LoadCountries.
LoadCountries RenewLocalCacheJob , ( ).
#1

#2


country.csv , CountryCode . cityCache countryLanguageCache; , .
.
.
:
- (SQL Server Management Studio):
- — 44 686 837;
- — 1.071 GB;
- — 0H:1M:35S;
- RenewLocalCacheJob reduce — 0H:0M:9S.
Dibutuhkan lebih sedikit waktu untuk mendistribusikan data ke seluruh cluster daripada mengeksekusi kueri SQL.