@ -121,6 +121,10 @@ public final class plasmaWordIndexDistribution {
}
}
}
}
private boolean isClosed ( ) {
return ( this . closed | | Thread . currentThread ( ) . isInterrupted ( ) ) ;
}
public boolean job ( ) {
public boolean job ( ) {
if ( this . closed ) {
if ( this . closed ) {
@ -194,13 +198,17 @@ public final class plasmaWordIndexDistribution {
if ( ( yacyCore . seedDB = = null ) | | ( yacyCore . seedDB . sizeConnected ( ) = = 0 ) ) return - 1 ;
if ( ( yacyCore . seedDB = = null ) | | ( yacyCore . seedDB . sizeConnected ( ) = = 0 ) ) return - 1 ;
// collect index
// collect index
plasmaWordIndexEntryContainer [ ] indexContainers = null ;
try {
String startPointHash = selectTransferStart ( ) ;
String startPointHash = selectTransferStart ( ) ;
log . logFine ( "Selected hash " + startPointHash + " as start point for index distribution, distance = " + yacyDHTAction . dhtDistance ( yacyCore . seedDB . mySeed . hash , startPointHash ) ) ;
this . log . logFine ( "Selected hash " + startPointHash + " as start point for index distribution, distance = " + yacyDHTAction . dhtDistance ( yacyCore . seedDB . mySeed . hash , startPointHash ) ) ;
Object [ ] selectResult = selectTransferContainers ( startPointHash , indexCount ) ;
Object [ ] selectResult = selectTransferContainers ( startPointHash , indexCount ) ;
plasmaWordIndexEntryContainer [ ] indexContainers = ( plasmaWordIndexEntryContainer [ ] ) selectResult [ 0 ] ;
indexContainers = ( plasmaWordIndexEntryContainer [ ] ) selectResult [ 0 ] ;
HashMap urlCache = ( HashMap ) selectResult [ 1 ] ; // String (url-hash) / plasmaCrawlLURL.Entry
HashMap urlCache = ( HashMap ) selectResult [ 1 ] ; // String (url-hash) / plasmaCrawlLURL.Entry
if ( ( indexContainers = = null ) | | ( indexContainers . length = = 0 ) ) {
if ( ( indexContainers = = null ) | | ( indexContainers . length = = 0 ) ) {
log. logFine ( "No index available for index transfer, hash start-point " + startPointHash ) ;
this . log. logFine ( "No index available for index transfer, hash start-point " + startPointHash ) ;
return - 1 ;
return - 1 ;
}
}
// count the indexes again, can be smaller as expected
// count the indexes again, can be smaller as expected
@ -209,8 +217,7 @@ public final class plasmaWordIndexDistribution {
indexCount + = indexContainers [ i ] . size ( ) ;
indexCount + = indexContainers [ i ] . size ( ) ;
}
}
if ( indexCount < 50 ) {
if ( indexCount < 50 ) {
log . logFine ( "Too few (" + indexCount + ") indexes selected for transfer." ) ;
this . log . logFine ( "Too few (" + indexCount + ") indexes selected for transfer." ) ;
closeTransferIndexes ( indexContainers ) ;
return - 1 ; // failed
return - 1 ; // failed
}
}
@ -227,8 +234,8 @@ public final class plasmaWordIndexDistribution {
double avdist ;
double avdist ;
Enumeration e = yacyCore . dhtAgent . getAcceptRemoteIndexSeeds ( keyhash ) ;
Enumeration e = yacyCore . dhtAgent . getAcceptRemoteIndexSeeds ( keyhash ) ;
while ( ( e . hasMoreElements ( ) ) & & ( hc0 < seeds . length ) ) {
while ( ( e . hasMoreElements ( ) ) & & ( hc0 < seeds . length ) ) {
if ( closed ) {
if ( this . isClosed ( ) ) {
log. logSevere ( "Index distribution interrupted by close, nothing deleted locally." ) ;
this . log. logSevere ( "Index distribution interrupted by close, nothing deleted locally." ) ;
return - 1 ; // interrupted
return - 1 ; // interrupted
}
}
seeds [ hc0 ] = ( yacySeed ) e . nextElement ( ) ;
seeds [ hc0 ] = ( yacySeed ) e . nextElement ( ) ;
@ -236,7 +243,7 @@ public final class plasmaWordIndexDistribution {
avdist = Math . max ( yacyDHTAction . dhtDistance ( seeds [ hc0 ] . hash , indexContainers [ 0 ] . wordHash ( ) ) ,
avdist = Math . max ( yacyDHTAction . dhtDistance ( seeds [ hc0 ] . hash , indexContainers [ 0 ] . wordHash ( ) ) ,
yacyDHTAction . dhtDistance ( seeds [ hc0 ] . hash , indexContainers [ indexContainers . length - 1 ] . wordHash ( ) ) ) ;
yacyDHTAction . dhtDistance ( seeds [ hc0 ] . hash , indexContainers [ indexContainers . length - 1 ] . wordHash ( ) ) ) ;
if ( avdist < maxDistance ) {
if ( avdist < maxDistance ) {
log. logInfo ( "Selected " + ( ( hc0 < peerCount ) ? "primary" : "reserve" ) + " DHT target peer " + seeds [ hc0 ] . getName ( ) + ":" + seeds [ hc0 ] . hash + ", distance = " + avdist ) ;
this . log. logInfo ( "Selected " + ( ( hc0 < peerCount ) ? "primary" : "reserve" ) + " DHT target peer " + seeds [ hc0 ] . getName ( ) + ":" + seeds [ hc0 ] . hash + ", distance = " + avdist ) ;
hc0 + + ;
hc0 + + ;
}
}
}
}
@ -245,8 +252,7 @@ public final class plasmaWordIndexDistribution {
}
}
if ( hc0 < peerCount ) {
if ( hc0 < peerCount ) {
log . logWarning ( "found not enough (" + hc0 + ") peers for distribution" ) ;
this . log . logWarning ( "found not enough (" + hc0 + ") peers for distribution" ) ;
closeTransferIndexes ( indexContainers ) ;
return - 1 ; // failed
return - 1 ; // failed
}
}
@ -256,8 +262,8 @@ public final class plasmaWordIndexDistribution {
long start ;
long start ;
int hc1 = 0 ;
int hc1 = 0 ;
for ( int i = 0 ; i < hc0 ; i + + ) {
for ( int i = 0 ; i < hc0 ; i + + ) {
if ( closed ) {
if ( this . isClosed ( ) ) {
log. logSevere ( "Index distribution interrupted by close, nothing deleted locally." ) ;
this . log. logSevere ( "Index distribution interrupted by close, nothing deleted locally." ) ;
return - 1 ; // interrupted
return - 1 ; // interrupted
}
}
start = System . currentTimeMillis ( ) ;
start = System . currentTimeMillis ( ) ;
@ -268,12 +274,12 @@ public final class plasmaWordIndexDistribution {
this . gzipBody4Distribution ,
this . gzipBody4Distribution ,
this . timeout4Distribution ) ;
this . timeout4Distribution ) ;
if ( error = = null ) {
if ( error = = null ) {
log. logInfo ( "Index transfer of " + indexCount + " words [" + indexContainers [ 0 ] . wordHash ( ) + " .. " + indexContainers [ indexContainers . length - 1 ] . wordHash ( ) + "] to peer " + seeds [ i ] . getName ( ) + ":" + seeds [ i ] . hash + " in " + ( ( System . currentTimeMillis ( ) - start ) / 1000 )
this . log. logInfo ( "Index transfer of " + indexCount + " words [" + indexContainers [ 0 ] . wordHash ( ) + " .. " + indexContainers [ indexContainers . length - 1 ] . wordHash ( ) + "] to peer " + seeds [ i ] . getName ( ) + ":" + seeds [ i ] . hash + " in " + ( ( System . currentTimeMillis ( ) - start ) / 1000 )
+ " seconds successfull (" + ( 1000 * indexCount / ( System . currentTimeMillis ( ) - start + 1 ) ) + " words/s)" ) ;
+ " seconds successfull (" + ( 1000 * indexCount / ( System . currentTimeMillis ( ) - start + 1 ) ) + " words/s)" ) ;
peerNames + = ", " + seeds [ i ] . getName ( ) ;
peerNames + = ", " + seeds [ i ] . getName ( ) ;
hc1 + + ;
hc1 + + ;
} else {
} else {
log. logWarning ( "Index transfer to peer " + seeds [ i ] . getName ( ) + ":" + seeds [ i ] . hash + " failed:'" + error + "', disconnecting peer" ) ;
this . log. logWarning ( "Index transfer to peer " + seeds [ i ] . getName ( ) + ":" + seeds [ i ] . hash + " failed:'" + error + "', disconnecting peer" ) ;
yacyCore . peerActions . peerDeparture ( seeds [ i ] ) ;
yacyCore . peerActions . peerDeparture ( seeds [ i ] ) ;
}
}
if ( hc1 > = peerCount ) break ;
if ( hc1 > = peerCount ) break ;
@ -285,18 +291,19 @@ public final class plasmaWordIndexDistribution {
// success
// success
if ( delete ) {
if ( delete ) {
int deletedURLs = deleteTransferIndexes ( indexContainers ) ;
int deletedURLs = deleteTransferIndexes ( indexContainers ) ;
log . logFine ( "Deleted from " + indexContainers . length + " transferred RWIs locally, removed " + deletedURLs + " URL references" ) ;
this . log . logFine ( "Deleted from " + indexContainers . length + " transferred RWIs locally, removed " + deletedURLs + " URL references" ) ;
indexContainers = null ;
return indexCount ;
return indexCount ;
} else {
// simply close the indexEntities
closeTransferIndexes ( indexContainers ) ;
}
}
return indexCount ;
return indexCount ;
} else {
}
log . logSevere ( "Index distribution failed. Too few peers (" + hc1 + ") received the index, not deleted locally." ) ;
this . log . logSevere ( "Index distribution failed. Too few peers (" + hc1 + ") received the index, not deleted locally." ) ;
return - 1 ;
} finally {
if ( indexContainers ! = null ) {
// simply close the indexEntities
// simply close the indexEntities
closeTransferIndexes ( indexContainers ) ;
closeTransferIndexes ( indexContainers ) ;
return - 1 ;
}
}
}
}
}