Changeset 14898 in josm


Ignore:
Timestamp:
2019-03-18T09:21:40+01:00 (6 years ago)
Author:
GerdP
Message:

fix #17291: improve handling of return code 404 in multifetch api

  • improve performance when server returns error code 404 (redacted): split workload into two halves instead of requesting each single id
  • reduce MAX_IDS_PER_REQUEST from 200 to 170 (this might decrease performace for large amounts of objects but should be safer)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/MultiFetchServerObjectReader.java

    r14214 r14898  
    6060public class MultiFetchServerObjectReader extends OsmServerReader {
    6161    /**
    62      * the max. number of primitives retrieved in one step. Assuming IDs with 7 digits,
    63      * this leads to a max. request URL of ~ 1600 Bytes ((7 digits +  1 Separator) * 200),
     62     * the max. number of primitives retrieved in one step. Assuming IDs with 10 digits,
     63     * this leads to a max. request URL of ~ 1900 Bytes ((10 digits +  1 Separator) * 170),
    6464     * which should be safe according to the
    6565     * <a href="http://www.boutell.com/newfaq/misc/urllength.html">WWW FAQ</a>.
    6666     */
    67     private static final int MAX_IDS_PER_REQUEST = 200;
     67    private static final int MAX_IDS_PER_REQUEST = 170;
    6868
    6969    private final Set<Long> nodes;
     
    335335            try {
    336336                FetchResult result = ecs.take().get();
     337                if (result.rc404 != null) {
     338                    List<Long> toSplit = new ArrayList<>(result.rc404);
     339                    int n = toSplit.size() / 2;
     340                    jobs.add(ecs.submit(new Fetcher(type, new HashSet<>(toSplit.subList(0, n)), progressMonitor)));
     341                    jobs.add(ecs.submit(new Fetcher(type, new HashSet<>(toSplit.subList(n, toSplit.size())), progressMonitor)));
     342                }
    337343                if (result.missingPrimitives != null) {
    338344                    missingPrimitives.addAll(result.missingPrimitives);
     
    428434        public final Set<PrimitiveId> missingPrimitives;
    429435
     436        private Set<Long> rc404;
     437
    430438        /**
    431439         * Constructs a {@code FetchResult}
     
    487495            } catch (OsmApiException e) {
    488496                if (e.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
     497                    if (pkg.size() > 4) {
     498                        FetchResult res = new FetchResult(null, null);
     499                        res.rc404 = pkg;
     500                        return res;
     501                    }
    489502                    Logging.info(tr("Server replied with response code 404, retrying with an individual request for each object."));
    490503                    return singleGetIdPackage(type, pkg, progressMonitor);
Note: See TracChangeset for help on using the changeset viewer.