|
1 | 1 | # ipgeolocation.io Database Reader |
2 | 2 |
|
3 | | -This is a step-by-step guide on how to deploy the ipgeolocation-database-reader-2.0.0.war Java API and consume API responses. |
| 3 | +This is a step-by-step guide on how to deploy the ipgeolocation-database-reader-2.0.1.war Java API and consume API responses. |
4 | 4 |
|
5 | 5 | ## What's New |
6 | 6 |
|
7 | | -- For `DB-V` `DB-VI` and `DB-VII`, the security database has been updated from a single IP format to an IP range format, optimizing memory usage while providing broader IP coverage. |
| 7 | +### 2.0.1 |
| 8 | +- **MMDB zero-downtime updates**: MMDB readers are now hot-swapped on update without restarting Tomcat, eliminating the 502 error window that occurred between shutdown and restart. |
| 9 | +- **Fixed MMDB crash on update**: new database files are written to a temporary path first and moved atomically to the live path, preventing the `InternalError` that occurred when a request hit the reader mid-overwrite. |
| 10 | +- **Faster database extraction**: ZIP extraction buffer increased from 1 KB to 64 KB, reducing extraction time from up to 30 minutes to seconds. |
| 11 | + |
| 12 | +### 2.0.0 |
| 13 | +- For `DB-V`, `DB-VI` and `DB-VII`, the security database has been updated from a single IP format to an IP range format, optimizing memory usage while providing broader IP coverage. |
8 | 14 |
|
9 | 15 | ## Requirements |
10 | 16 |
|
11 | 17 | - JDK 8 (This reader is built and tested using JDK 1.8). |
12 | 18 | - For CSV databases, at least 4-8 GB RAM (for smaller CSV databases) and maximum 16 GB RAM for larger databases like DB-IV, DB-VI, and DB-VII. |
13 | 19 | - For MMDB databases, at least 2-4 GB RAM only. |
14 | | -- ipgeolocation-database-reader-2.0.0.war provided with this archive. |
| 20 | +- ipgeolocation-database-reader-2.0.1.war provided with this archive. |
15 | 21 |
|
16 | 22 | ## Basic Usage |
17 | 23 |
|
@@ -45,26 +51,26 @@ Follow the steps below (commands against each step are also provided) to deploy |
45 | 51 | * Against `updateInterval` key, replace `week` value with your database subscription update interval. It can be `week`, or `month`. |
46 | 52 | * Against `type` key, replace `mmdb` value with your choice of database to query from. It can be `csv`, or `mmdb`. It's default value is `mmdb` and can be skipped from configuration. |
47 | 53 | * Against `autoFetchAndUpdate` key, the value can be `true` or `false`. |
48 | | - - If set to `true`, the database reader will download the latest database as soon as it is available and will restart to load the latest database in-memory. |
| 54 | + - If set to `true`, the database reader will automatically download the latest database as soon as it is available. For MMDB, the new database is loaded in-memory without any restart or downtime. For CSV, the service restarts to reload the updated database. |
49 | 55 | - If set to `false`, the database reader will not check for the updated database for you. You can send a POST request to `/database/update` endpoint to fetch and update the database in-memory if an update is available. For example, here is a cURL request: `curl --location --request POST 'http://address-to-api:8080/database/update'` |
50 | 56 | - It's default value is `true` and can be skipped from configuration. |
51 | 57 | - Run the WAR file (if you placed config file at default path `~/conf/ipgeolocation`) |
52 | 58 | ```bash |
53 | | - java -jar -Xms6G -Xmx10G /path/to/ipgeolocation-database-reader-2.0.0.war |
| 59 | + java -jar -Xms6G -Xmx10G /path/to/ipgeolocation-database-reader-2.0.1.war |
54 | 60 | ``` |
55 | | - Note: Use -Xms<ram_size1> flag to set the minimum RAM and -Xmx<ram_size2> to set the maximum RAM to be allocated to execute the 'ipgeolocation-database-reader-2.0.0.war' application. |
| 61 | + Note: Use -Xms<ram_size1> flag to set the minimum RAM and -Xmx<ram_size2> to set the maximum RAM to be allocated to execute the 'ipgeolocation-database-reader-2.0.1.war' application. |
56 | 62 | Note: ram_size1 is the minimum RAM, and ram_size2 is the maximum RAM allocated to the application. |
57 | 63 | Note: You can deploy the WAR file in an embedded container like Apache Tomcat as well. |
58 | 64 |
|
59 | 65 | The database reader will download the latest database and load it in-memory while bootstrapping and will update the database as soon as the new update is available, if `autoFetchAndUpdate` is set to `true`. |
60 | 66 |
|
61 | | -**Note:** database reader needs to restart after fetching the latest database to cache the updated database in-memory because caching the database without restarting will require as much as double of the required RAM which is a very costly choice. |
| 67 | +**Note:** For MMDB, the reader hot-swaps the database in-memory with no restart and no downtime. For CSV, the reader restarts after fetching the latest database because reloading large CSV databases in-memory without a restart would require up to double the RAM. |
62 | 68 |
|
63 | 69 | ### Other Ways to Provide Configurations |
64 | 70 |
|
65 | 71 | By default, the database reader will look at `~/conf/ipgeolocation/database-reader-config.yaml` path for the YAML file. You can provide the YAML configurations from your custom location as well. Let's assume that you've created the YAML configurations at `/etc/ipgeolocation/ipgeo-db-reader-conf.yaml`. Here is how you can pass it to the database reader: |
66 | 72 | ```bash |
67 | | -java -Dspring.config.import=file:/etc/ipgeolocation/ipgeo-db-reader-conf.yaml -jar -Xms6G -Xmx10G /path/to/ipgeolocation-database-reader-2.0.0.war |
| 73 | +java -Dspring.config.import=file:/etc/ipgeolocation/ipgeo-db-reader-conf.yaml -jar -Xms6G -Xmx10G /path/to/ipgeolocation-database-reader-2.0.1.war |
68 | 74 | ``` |
69 | 75 |
|
70 | 76 | ### For Windows |
@@ -99,25 +105,25 @@ mkdir conf\ipgeolocation |
99 | 105 | * Against `updateInterval` key, replace `week` value with your database subscription update interval. It can be `week`, or `month`. |
100 | 106 | * Against `type` key, replace `mmdb` value with your choice of database to query from. It can be `csv`, or `mmdb`. It's default value is `mmdb` and can be skipped from configuration. |
101 | 107 | * Against `autoFetchAndUpdate` key, the value can be `true` or `false`. |
102 | | - - If set to `true`, the database reader will download the latest database as soon as it is available and will restart to load the latest database in-memory. |
| 108 | + - If set to `true`, the database reader will automatically download the latest database as soon as it is available. For MMDB, the new database is loaded in-memory without any restart or downtime. For CSV, the service restarts to reload the updated database. |
103 | 109 | - If set to `false`, the database reader will not check for the updated database for you. You can send a POST request to `/database/update` endpoint to fetch and update the database in-memory if an update is available. For example, here is a cURL request: `curl --location --request POST 'http://address-to-api:8080/database/update'` |
104 | 110 | - It's default value is `true` and can be skipped from configuration. |
105 | 111 | - Run the WAR file |
106 | 112 | ```bash |
107 | | - java -jar -Xms4G -Xmx4G -Dspring.config.import=file:C:\\conf\\ipgeolocation\\database-reader-config.yml C:\path\to\ipgeolocation-database-reader-2.0.0.war |
| 113 | + java -jar -Xms4G -Xmx4G -Dspring.config.import=file:C:\\conf\\ipgeolocation\\database-reader-config.yml C:\path\to\ipgeolocation-database-reader-2.0.1.war |
108 | 114 | ``` |
109 | | - Note: Use -Xms<ram_size1> flag to set the minimum RAM and -Xmx<ram_size2> to set the maximum RAM to be allocated to execute the 'ipgeolocation-database-reader-2.0.0.war' application. |
| 115 | + Note: Use -Xms<ram_size1> flag to set the minimum RAM and -Xmx<ram_size2> to set the maximum RAM to be allocated to execute the 'ipgeolocation-database-reader-2.0.1.war' application. |
110 | 116 | Note: ram_size1 is the minimum RAM, and ram_size2 is the maximum RAM allocated to the application. |
111 | 117 | Note: You can deploy the WAR file in an embedded container like Apache Tomcat as well. |
112 | 118 |
|
113 | 119 | The database reader will download the latest database and load it in-memory while bootstrapping and will update the database as soon as the new update is available, if `autoFetchAndUpdate` is set to `true`. |
114 | 120 |
|
115 | | -**Note:** database reader needs to restart after fetching the latest database to cache the updated database in-memory because caching the database without restarting will require as much as double of the required RAM which is a very costly choice. |
| 121 | +**Note:** For MMDB, the reader hot-swaps the database in-memory with no restart and no downtime. For CSV, the reader restarts after fetching the latest database because reloading large CSV databases in-memory without a restart would require up to double the RAM. |
116 | 122 |
|
117 | 123 | Another way is not create a YAML file and provide the configurations as the command-line arguments to the `war` file. Here is how you can do that: |
118 | 124 |
|
119 | 125 | ```bash |
120 | | -java -Dipgeolocation.database.workingDirectory=/etc/ipgeolocation -Dipgeolocation.database.apiKey=YOUR_API_KEY -Dipgeolocation.database.version=DB-VII -Dipgeolocation.database.updateInterval=week -Dipgeolocation.database.type=mmdb -Dipgeolocation.database.autoFetchAndUpdate=false -jar -Xms6G -Xmx10G /path/to/ipgeolocation-database-reader-2.0.0.war |
| 126 | +java -Dipgeolocation.database.workingDirectory=/etc/ipgeolocation -Dipgeolocation.database.apiKey=YOUR_API_KEY -Dipgeolocation.database.version=DB-VII -Dipgeolocation.database.updateInterval=week -Dipgeolocation.database.type=mmdb -Dipgeolocation.database.autoFetchAndUpdate=false -jar -Xms6G -Xmx10G /path/to/ipgeolocation-database-reader-2.0.1.war |
121 | 127 | ``` |
122 | 128 |
|
123 | 129 | ## How to Get IP Geolocation |
|
0 commit comments