18
18
import org .commonjava .indy .IndyWorkflowException ;
19
19
import org .commonjava .indy .content .ContentManager ;
20
20
import org .commonjava .indy .content .index .conf .ContentIndexConfig ;
21
- import org .commonjava .indy .content .index .deindex .DeIndexHandlingCache ;
22
- import org .commonjava .indy .content .index .deindex .DeIndexHandlingCacheListener ;
23
- import org .commonjava .indy .content .index .deindex .DeIndexInfo ;
24
21
import org .commonjava .indy .core .content .PathMaskChecker ;
25
22
import org .commonjava .indy .data .IndyDataException ;
26
23
import org .commonjava .indy .data .StoreDataManager ;
27
24
import org .commonjava .indy .measure .annotation .Measure ;
25
+ import org .commonjava .indy .measure .annotation .MetricNamed ;
28
26
import org .commonjava .indy .model .core .ArtifactStore ;
29
27
import org .commonjava .indy .model .core .Group ;
30
28
import org .commonjava .indy .model .core .HostedRepository ;
31
29
import org .commonjava .indy .model .core .StoreKey ;
32
30
import org .commonjava .indy .model .core .StoreType ;
33
31
import org .commonjava .indy .model .galley .KeyedLocation ;
34
- import org .commonjava .indy .subsys .infinispan .CacheHandle ;
35
32
import org .commonjava .indy .util .LocationUtils ;
36
33
import org .commonjava .maven .galley .event .EventMetadata ;
37
34
import org .commonjava .maven .galley .model .ConcreteResource ;
43
40
import org .slf4j .Logger ;
44
41
import org .slf4j .LoggerFactory ;
45
42
46
- import javax .annotation .PostConstruct ;
47
43
import javax .decorator .Decorator ;
48
44
import javax .decorator .Delegate ;
49
45
import javax .enterprise .inject .Any ;
56
52
import java .util .Objects ;
57
53
import java .util .Set ;
58
54
59
- import static org .commonjava .indy .content .index .deindex .DeIndexInfo .TYPE_MULTI ;
60
- import static org .commonjava .indy .content .index .deindex .DeIndexInfo .TYPE_SINGLE ;
61
55
import static org .commonjava .indy .core .content .group .GroupMergeHelper .GROUP_METADATA_EXISTS ;
62
56
import static org .commonjava .indy .core .content .group .GroupMergeHelper .GROUP_METADATA_GENERATED ;
57
+ import static org .commonjava .indy .measure .annotation .MetricNamed .DEFAULT ;
63
58
64
59
/**
65
60
* Decorator for ContentManager which uses Infinispan to index content to avoid having to iterate all members of large
@@ -93,14 +88,6 @@ public abstract class IndexingContentManagerDecorator
93
88
@ Inject
94
89
private ContentIndexConfig indexCfg ;
95
90
96
- @ Inject
97
- @ DeIndexHandlingCache
98
- private CacheHandle <Long , DeIndexInfo > deIndexQueue ;
99
-
100
- @ Inject
101
- private DeIndexHandlingCacheListener deIndexHandler ;
102
-
103
-
104
91
protected IndexingContentManagerDecorator ()
105
92
{
106
93
}
@@ -125,27 +112,6 @@ protected IndexingContentManagerDecorator( final ContentManager delegate, final
125
112
this .indexCfg = indexCfg ;
126
113
}
127
114
128
- protected IndexingContentManagerDecorator ( final ContentManager delegate , final StoreDataManager storeDataManager ,
129
- final SpecialPathManager specialPathManager ,
130
- final ContentIndexManager indexManager , final NotFoundCache nfc ,
131
- final ContentIndexConfig indexCfg ,
132
- final CacheHandle <Long , DeIndexInfo > deIndexQueue ,
133
- final DeIndexHandlingCacheListener deIndexHandler )
134
- {
135
- this ( delegate , storeDataManager , specialPathManager , indexManager , nfc , indexCfg );
136
- this .deIndexQueue = deIndexQueue ;
137
- this .deIndexHandler = deIndexHandler ;
138
- }
139
-
140
- @ PostConstruct
141
- public void init ()
142
- {
143
- deIndexQueue .executeCache ( c -> {
144
- c .addListener ( deIndexHandler );
145
- return null ;
146
- } );
147
- }
148
-
149
115
@ Override
150
116
public Transfer retrieveFirst ( final List <? extends ArtifactStore > stores , final String path )
151
117
throws IndyWorkflowException
@@ -234,7 +200,7 @@ public Transfer retrieve( final ArtifactStore store, final String path, final Ev
234
200
else if ( isAuthoritativelyMissing ( store ) )
235
201
{
236
202
logger .debug (
237
- "Not found indexed transfer: {} and authoritative index switched on. Considering not found and return null." , transfer );
203
+ "Not found indexed transfer: {} and authoritative index switched on. Considering not found and return null." );
238
204
return null ;
239
205
}
240
206
@@ -492,7 +458,7 @@ public Transfer getTransfer( final ArtifactStore store, final String path, final
492
458
else if ( isAuthoritativelyMissing ( store ) )
493
459
{
494
460
logger .info (
495
- "Not found indexed transfer: {} and authoritative index switched on. Considering not found and return null." , transfer );
461
+ "Not found indexed transfer: {} and authoritative index switched on. Considering not found and return null." );
496
462
return null ;
497
463
}
498
464
@@ -544,7 +510,7 @@ else if ( isAuthoritativelyMissing( store ) )
544
510
return transfer ;
545
511
}
546
512
547
- @ Measure
513
+ @ Measure ( timers = @ MetricNamed ( DEFAULT ), exceptions = @ MetricNamed ( DEFAULT ) )
548
514
@ Deprecated
549
515
public Transfer getIndexedMemberTransfer ( final Group group , final String path , TransferOperation op ,
550
516
ContentManagementFunction func , final EventMetadata metadata )
@@ -636,7 +602,7 @@ public Transfer getTransfer( final StoreKey storeKey, final String path, final T
636
602
637
603
if ( isAuthoritativelyMissing ( store ) )
638
604
{
639
- logger .debug ( "Not found indexed transfer: {} and authoritative index switched on. Return null." , transfer );
605
+ logger .debug ( "Not found indexed transfer: {} and authoritative index switched on. Return null." );
640
606
return null ;
641
607
}
642
608
@@ -730,11 +696,41 @@ public Transfer store( final ArtifactStore store, final String path, final Input
730
696
{
731
697
Logger logger = LoggerFactory .getLogger ( getClass () );
732
698
logger .trace ( "Storing: {} in: {} from indexing level" , path , store .getKey () );
733
- final Transfer transfer = delegate .store ( store , path , stream , op , eventMetadata );
734
- //NOSSUP-87 & NOS-2233: As the getGroupsAffectedBy is a time-consumed ops which is killing the
735
- //upload performance, and seems the de-index ops for the uploaded path is not a big factor to
736
- //affect following operations, we should think about to async it here.
737
- deIndexQueue .put ( System .currentTimeMillis (), new DeIndexInfo ( transfer , store , TYPE_SINGLE ) );
699
+ Transfer transfer = delegate .store ( store , path , stream , op , eventMetadata );
700
+ if ( transfer != null )
701
+ {
702
+ if ( indexCfg .isEnabled () )
703
+ {
704
+ logger .trace ( "Indexing: {} in: {}" , transfer , store .getKey () );
705
+ indexManager .indexTransferIn ( transfer , store .getKey () );
706
+ }
707
+
708
+ if ( store instanceof Group )
709
+ {
710
+ nfc .clearMissing ( new ConcreteResource ( LocationUtils .toLocation ( store ), path ) );
711
+ }
712
+ // We should deIndex the path for all parent groups because the new content of the path
713
+ // may change the content index sequence based on the constituents sequence in parent groups
714
+ if ( store .getType () == StoreType .hosted )
715
+ {
716
+ try
717
+ {
718
+ Set <Group > groups = storeDataManager .query ().getGroupsAffectedBy ( store .getKey () );
719
+ if ( groups != null && !groups .isEmpty () && indexCfg .isEnabled () )
720
+ {
721
+ groups .forEach ( g -> indexManager .deIndexStorePath ( g .getKey (), path ) );
722
+ }
723
+ }
724
+ catch ( IndyDataException e )
725
+ {
726
+ throw new IndyWorkflowException (
727
+ "Failed to get groups which contains: %s for NFC handling. Reason: %s" , e , store .getKey (),
728
+ e .getMessage () );
729
+ }
730
+
731
+ }
732
+ }
733
+ // nfcClearByContaining( store, path );
738
734
739
735
return transfer ;
740
736
}
@@ -751,8 +747,34 @@ public Transfer store( final List<? extends ArtifactStore> stores, final StoreKe
751
747
final InputStream stream , final TransferOperation op , final EventMetadata eventMetadata )
752
748
throws IndyWorkflowException
753
749
{
754
- final Transfer transfer = delegate .store ( stores , topKey , path , stream , op , eventMetadata );
755
- deIndexQueue .put ( System .currentTimeMillis (), new DeIndexInfo ( transfer , null , topKey , TYPE_MULTI ) );
750
+ Transfer transfer = delegate .store ( stores , topKey , path , stream , op , eventMetadata );
751
+ if ( transfer != null )
752
+ {
753
+ if ( indexCfg .isEnabled () )
754
+ {
755
+ indexManager .indexTransferIn ( transfer , topKey );
756
+ }
757
+
758
+ try
759
+ {
760
+ ArtifactStore topStore = storeDataManager .getArtifactStore ( topKey );
761
+ nfc .clearMissing ( new ConcreteResource ( LocationUtils .toLocation ( topStore ), path ) );
762
+
763
+ if ( indexCfg .isEnabled () )
764
+ {
765
+ // We should deIndex the path for all parent groups because the new content of the path
766
+ // may change the content index sequence based on the constituents sequence in parent groups
767
+ indexManager .deIndexStorePath ( topKey , path );
768
+ }
769
+ }
770
+ catch ( IndyDataException e )
771
+ {
772
+ Logger logger = LoggerFactory .getLogger ( getClass () );
773
+ logger .error ( String .format ( "Failed to retrieve top store: %s for NFC management. Reason: %s" ,
774
+ topKey , e .getMessage ()), e );
775
+ }
776
+ }
777
+
756
778
return transfer ;
757
779
}
758
780
0 commit comments