/** * Cloning constructor. */ public ObjectConfig(ObjectConfig<T> other) { this.protocol = other.protocol; // deep copy the VDCs to avoid two clients referencing the same host lists (SDK-122) this.vdcs = new ArrayList<Vdc>(); for (Vdc vdc : other.getVdcs()) { this.vdcs.add(new Vdc(vdc.getName(), vdc.getHosts())); } this.port = other.port; this.smartClient = other.smartClient; this.rootContext = other.rootContext; this.namespace = other.namespace; this.identity = other.identity; this.secretKey = other.secretKey; this.serverClockSkew = other.serverClockSkew; this.userAgent = other.userAgent; this.geoPinningEnabled = other.geoPinningEnabled; this.geoReadRetryFailover = other.geoReadRetryFailover; this.chunkedEncodingSize = other.chunkedEncodingSize; this.properties = new HashMap<String, Object>(other.properties); }
@Override public ClientResponse handle(ClientRequest request) throws ClientHandlerException { // if there's no bucket, we don't need to pin the request (there's no write or read) String bucketName = (String) request.getProperties().get(S3Constants.PROPERTY_BUCKET_NAME); String objectKey = (String) request.getProperties().get(S3Constants.PROPERTY_OBJECT_KEY); if (bucketName != null) { List<Vdc> healthyVdcs = new ArrayList<Vdc>(); for (Vdc vdc : objectConfig.getVdcs()) { if (vdc.isHealthy()) healthyVdcs.add(vdc); } if (healthyVdcs.isEmpty()) { log.debug("there are no healthy VDCs; geo-pinning will include all VDCs"); healthyVdcs.addAll(objectConfig.getVdcs()); } int geoPinIndex = getGeoPinIndex(getGeoId(bucketName, objectKey), healthyVdcs.size()); // if this is a read and failover for retries is requested, round-robin the VDCs for each retry if (objectConfig.isGeoReadRetryFailover() && Method.GET.name().equalsIgnoreCase(request.getMethod())) { Integer retries = (Integer) request.getProperties().get(RetryFilter.PROP_RETRY_COUNT); if (retries != null) { int newIndex = (geoPinIndex + retries) % healthyVdcs.size(); log.info("geo-pin read retry #{}: failing over from primary VDC {} to VDC {}", retries, geoPinIndex, newIndex); geoPinIndex = newIndex; } } request.getProperties().put(GeoPinningRule.PROP_GEO_PINNED_VDC, healthyVdcs.get(geoPinIndex)); } return getNext().handle(request); }