Skip to content

Commit 914767e

Browse files
authored
Merge pull request #733 from maxmind/greg/docs-windows-memory-map-lock
Clarify Windows memory-map file locking and fix Javadoc issues
2 parents dddbb3b + acdb7fd commit 914767e

9 files changed

Lines changed: 98 additions & 82 deletions

File tree

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,24 @@ Maven, you must
286286
Failure to do so will result in `InvalidDatabaseException` exceptions being
287287
thrown when querying the database.
288288

289+
### File Lock on Windows ###
290+
291+
By default, the `DatabaseReader` uses the `MEMORY_MAPPED` file mode, which
292+
memory maps the database file. On Windows, a live memory mapping may prevent
293+
the file from being renamed, replaced, or deleted. This is not a Java
294+
`FileLock`, but it can have similar effects when updating a database file in
295+
place.
296+
297+
Closing the `DatabaseReader` releases its reference to the mapped buffer, but
298+
Java does not provide a supported way to unmap the underlying
299+
`MappedByteBuffer` immediately. The mapping remains valid until the buffer
300+
becomes unreachable and is garbage collected.
301+
302+
To avoid this behavior, configure the `Builder` with `FileMode.MEMORY`. If you
303+
must use `MEMORY_MAPPED`, close and dereference the `DatabaseReader` before
304+
replacing the file. You may call `System.gc()` to encourage earlier cleanup,
305+
but garbage collection is not guaranteed to run immediately.
306+
289307
## Database Example ##
290308

291309
### City ###

lychee.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# lychee './**/*.md' './src/**/*.java' './pom.xml'
66

77
# Include URL fragments in checks
8-
include_fragments = true
8+
include_fragments = "full"
99

1010
# Don't allow any redirects, so links that have moved are surfaced and updated
1111
# to their canonical destination.

mise.lock

Lines changed: 49 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/maxmind/geoip2/DatabaseProvider.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Optional<CityResponse> tryCity(InetAddress ipAddress) throws IOException,
4242
* Look up an IP address in a GeoIP Anonymous IP.
4343
*
4444
* @param ipAddress IPv4 or IPv6 address to lookup.
45-
* @return a AnonymousIpResponse for the requested IP address.
45+
* @return an AnonymousIpResponse for the requested IP address.
4646
* @throws com.maxmind.geoip2.exception.GeoIp2Exception if there is an error looking up the IP
4747
* @throws java.io.IOException if there is an IO error
4848
*/
@@ -53,7 +53,7 @@ AnonymousIpResponse anonymousIp(InetAddress ipAddress) throws IOException,
5353
* Look up an IP address in a GeoIP Anonymous IP.
5454
*
5555
* @param ipAddress IPv4 or IPv6 address to lookup.
56-
* @return a AnonymousIpResponse for the requested IP address or empty if it is not in the DB.
56+
* @return an AnonymousIpResponse for the requested IP address or empty if it is not in the DB.
5757
* @throws com.maxmind.geoip2.exception.GeoIp2Exception if there is an error looking up the IP
5858
* @throws java.io.IOException if there is an IO error
5959
*/
@@ -64,7 +64,7 @@ Optional<AnonymousIpResponse> tryAnonymousIp(InetAddress ipAddress) throws IOExc
6464
* Look up an IP address in a GeoIP Anonymous Plus.
6565
*
6666
* @param ipAddress IPv4 or IPv6 address to lookup.
67-
* @return a AnonymousPlusResponse for the requested IP address.
67+
* @return an AnonymousPlusResponse for the requested IP address.
6868
* @throws com.maxmind.geoip2.exception.GeoIp2Exception if there is an error looking up the IP
6969
* @throws java.io.IOException if there is an IO error
7070
*/
@@ -75,7 +75,8 @@ AnonymousPlusResponse anonymousPlus(InetAddress ipAddress) throws IOException,
7575
* Look up an IP address in a GeoIP Anonymous Plus.
7676
*
7777
* @param ipAddress IPv4 or IPv6 address to lookup.
78-
* @return a AnonymousPlusResponse for the requested IP address or empty if it is not in the DB.
78+
* @return an AnonymousPlusResponse for the requested IP address or empty if it
79+
* is not in the DB.
7980
* @throws com.maxmind.geoip2.exception.GeoIp2Exception if there is an error looking up the IP
8081
* @throws java.io.IOException if there is an IO error
8182
*/
@@ -97,7 +98,7 @@ IpRiskResponse ipRisk(InetAddress ipAddress) throws IOException,
9798
* Look up an IP address in a GeoIP IP Risk database.
9899
*
99100
* @param ipAddress IPv4 or IPv6 address to lookup.
100-
* @return an IPRiskResponse for the requested IP address or empty if it is not in the DB.
101+
* @return an IpRiskResponse for the requested IP address or empty if it is not in the DB.
101102
* @throws com.maxmind.geoip2.exception.GeoIp2Exception if there is an error looking up the IP
102103
* @throws java.io.IOException if there is an IO error
103104
*/
@@ -108,7 +109,7 @@ Optional<IpRiskResponse> tryIpRisk(InetAddress ipAddress) throws IOException,
108109
* Look up an IP address in a GeoLite ASN database.
109110
*
110111
* @param ipAddress IPv4 or IPv6 address to lookup.
111-
* @return an IspResponse for the requested IP address.
112+
* @return an AsnResponse for the requested IP address.
112113
* @throws com.maxmind.geoip2.exception.GeoIp2Exception if there is an error looking up the IP
113114
* @throws java.io.IOException if there is an IO error
114115
*/
@@ -119,7 +120,7 @@ AsnResponse asn(InetAddress ipAddress) throws IOException,
119120
* Look up an IP address in a GeoLite ASN database.
120121
*
121122
* @param ipAddress IPv4 or IPv6 address to lookup.
122-
* @return an IspResponse for the requested IP address or empty if it is not in the DB.
123+
* @return an AsnResponse for the requested IP address or empty if it is not in the DB.
123124
* @throws com.maxmind.geoip2.exception.GeoIp2Exception if there is an error looking up the IP
124125
* @throws java.io.IOException if there is an IO error
125126
*/
@@ -130,7 +131,7 @@ Optional<AsnResponse> tryAsn(InetAddress ipAddress) throws IOException,
130131
* Look up an IP address in a GeoIP Connection Type database.
131132
*
132133
* @param ipAddress IPv4 or IPv6 address to lookup.
133-
* @return a ConnectTypeResponse for the requested IP address.
134+
* @return a ConnectionTypeResponse for the requested IP address.
134135
* @throws com.maxmind.geoip2.exception.GeoIp2Exception if there is an error looking up the IP
135136
* @throws java.io.IOException if there is an IO error
136137
*/
@@ -141,7 +142,8 @@ ConnectionTypeResponse connectionType(InetAddress ipAddress)
141142
* Look up an IP address in a GeoIP Connection Type database.
142143
*
143144
* @param ipAddress IPv4 or IPv6 address to lookup.
144-
* @return a ConnectTypeResponse for the requested IP address or empty if it is not in the DB.
145+
* @return a ConnectionTypeResponse for the requested IP address or empty if it
146+
* is not in the DB.
145147
* @throws com.maxmind.geoip2.exception.GeoIp2Exception if there is an error looking up the IP
146148
* @throws java.io.IOException if there is an IO error
147149
*/
@@ -206,8 +208,8 @@ IspResponse isp(InetAddress ipAddress) throws IOException,
206208
/**
207209
* Look up an IP address in a GeoIP ISP database.
208210
*
209-
* @param ipAddress IPv4 or IPv6 address to look up or empty if it is not in the DB.
210-
* @return an IspResponse for the requested IP address.
211+
* @param ipAddress IPv4 or IPv6 address to look up.
212+
* @return an IspResponse for the requested IP address or empty if it is not in the DB.
211213
* @throws com.maxmind.geoip2.exception.GeoIp2Exception if there is an error looking up the IP
212214
* @throws java.io.IOException if there is an IO error
213215
*/

0 commit comments

Comments
 (0)