1020 Commits

Author SHA1 Message Date
Han-Wen Nienhuys
33ef2b8754 Expose names and URLs for invisible groups in GetAccess
This sounds counter-intuitive, but this is feature compatible with the
GWT UI, which uses the GWT RPC interface.

Change-Id: I53a0f00684b33634883aaa9ecb7f2fd294456f5f
2018-02-15 14:13:44 +01:00
Alice Kober-Sotzek
a6b29e06b8 GroupIndexer: Remove reindex if stale after original index update
The race condition which exists for the change index (see I04ac36ea55a)
doesn't exist for the group index. Contrary to the change index, the
group index always uses the current value from the primary storage when
updating the index.

Let's assume that we have two concurrent updates of a group.
1. Updater A writes group in state A to primary storage.
2. Updater B writes group in state B to primary storage.
3. Updater B updates the index with state B from primary storage.
4. Updater A updates the index with state B from primary storage.

So, even when the writes to the storage and the updates of the index are
executed in an arbitrary order, the index still contains the correct
value in the end.

Change-Id: I1965b20c3d493ab05ec5d9636b9ac07f9ea3132b
2018-02-15 13:29:05 +01:00
Alice Kober-Sotzek
adf3afaaf7 Make sure to never use cached values when indexing groups
Indexed groups are retrieved from the group cache. As group caches may
possibly have stale entries (for example when in slave mode), we have to
be careful not to use outdated values. All code paths which referred to
the GroupIndexer correctly invalidated the group cache. Requiring the
cache evictions in other classes is a bit dangerous, though.

This situation becomes even worse with the recently added
GroupIndexer#reindexIfStale method. Whether the group index is stale is
determined by comparing the group stored in the index with the one
stored in NoteDb. For updating a stale index entry, we didn't ensure
that the group was freshly read from NoteDb. This means that users of
GroupIndexer#reindexIfStale which care about up-to-date values would
need to manually invalidate the cache, which would trigger an indexing
without the stale check, and hence make the call to
GroupIndexer#reindexIfStale obsolete. Alternatively, they would need to
accept outdated values without any guarantee when they are updated.

To prevent future errors due to missing cache invalidations and to allow
calling GroupIndexer#index and GroupIndexer#reindexIfStale even with
stale caches (e.g. in slave mode), we explicitly use a non-cached value
for indexing now.

As the necessity for manual cache evictions is removed, it makes sense
in other parts of the code to not indirectly trigger an indexing for a
group by evicting it from the cache but to explicitly call the indexer.

As a result, evicting an element from the cache doesn't need to trigger
an indexing anymore. Previously, this was a bit confusing as it wasn't
explicitly documented in Javadoc and only happened for GroupCache#evict
and GroupCache#onCreateGroup but not for GroupCache#evictRename. It
would also have created an infinite loop for the new eviction in the
indexer.

In addition, grouping several evictions into GroupCache#evict made it
complicated to get a non-cached value from
GroupCache#get(AccountGroup.UUID). If just the group UUID was available,
this required that a group had to be loaded first from the cache via
GroupCache#get(AccountGroup.UUID), then evicted, and then loaded again.
As the first loading doesn't necessarily need to retrieve a cached
value, the group might have been loaded twice from storage.

For AllGroupsIndexer, there was even a possibly unintended side-effect:
The cache invalidation triggered an indirect indexing for the group
before the group was retrieved from the cache and explicitly put in the
index. The adjusted code should avoid this situation by only doing all
interaction with the index in AllGroupsIndexer.

We also use the opportunity to add some tests for the GroupIndexer and
the adjusted behavior.

Change-Id: I0b281d7b72831d78462f7a7ac5e57a67d09d980b
2018-02-15 13:28:54 +01:00
Edwin Kempin
0dd475241b AccountConfig: Remove lazy parsing of project watches and preferences
Nobody is making use of this. The only usage was removed by change
Id020fd8972. As explained in the commit message of change Id020fd8972 it
turned out that lazy parsing leads to a memory leak because for this the
reference to AccountConfig needs to be kept in memory and AccountConfig
may need quite a lot of memory since it holds an open Repository
instance.

Lazy parsing was not really needed and turned out to be a classic case
of premature optimization.

Change-Id: I534cfc0eeb01e0ccd4af3df3986fa23112f7cb63
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-15 10:11:40 +01:00
Patrick Hiesel
33f5bd2506 Merge changes I19e5238f,Iebf10771
* changes:
  ProtoGen: Don't include version in output
  ProtoGen: Don't output anything on success
2018-02-15 07:35:15 +00:00
David Ostrovsky
8e946e8ee8 Fix implicitly cc on non voting review for users without username
This change partially reverts changes done in I97e33caa8e.

Bug: Issue 8377
Change-Id: I9f9c5c3655592d8f7d0b2af330005e9289ea1f81
2018-02-14 23:17:32 +01:00
David Ostrovsky
befa751c41 DefaultAdvertiseRefsHook: Fix Eclipse javadoc warning
This fixes: "Javadoc: Invalid member type qualification" warning.

Change-Id: I6210a0e32af2e97da1d44742c914c4ddfbd9914b
2018-02-14 23:09:34 +01:00
Dave Borowitz
b90f608922 ProtoGen: Don't include version in output
Google is the only user of this, and we no longer need this file to
change every time we import Gerrit.

Change-Id: I19e5238f236ec47c9893b74780cfe9768a1b5d78
2018-02-14 13:27:34 -05:00
Dave Borowitz
30ee47cd6b ProtoGen: Don't output anything on success
Many well-behaved Unix programs succeed silently. Simply repeating the
filename argument isn't providing any benefit.

Change-Id: Iebf1077109003709592419e2381394ff29416aea
2018-02-14 13:27:34 -05:00
Patrick Hiesel
f6fd2307bd Cache DefaultRefFilter to speed up subsequent filter() calls
DefaultRefFilter has a Map of visible changes as internal state. Reusing
this map in subsequent calls speeds the operation up.

Change-Id: Idb8627138badfeb3182b5904c3d569789334366c
2018-02-14 16:49:33 +01:00
Patrick Hiesel
3ee59ad132 Remove READ_NO_CONFIG permission
Now that DefaultRefFilter is an implementation detail of
PermissionBackend we can remove READ_NO_CONFIG as it was only used to
migrate all callers away from direct calls to *Control classes.

Change-Id: I5bf0a6f59cf66b3720c2cb2b671d821eceb593bb
2018-02-14 15:13:31 +00:00
Patrick Hiesel
f9891ee61d Merge "Move VisibleRefFilter into PermissionBackend" 2018-02-14 15:13:16 +00:00
Patrick Hiesel
77fd024638 Move VisibleRefFilter into PermissionBackend
This commit adds signatures to filter refs by visibility to
PermissionBackend.ForProject.

VisibleRefFilter is renamed to DefaultRefFilter and moved into the
permissions package. Minor changes to the class make it fit better into
the new interface structure and make the class easier to read.

Instead of offering config options on the class, this commit adds an
Options AutoValue and forces callers to provide an open repository
handler to the filter method.

Change-Id: I1819de0bab81ed546f1c35461cc5361f1c4027ba
2018-02-14 14:42:05 +01:00
Edwin Kempin
0705881a1e RelatedChangesSorter.PatchSetData: Add missing equals method
This class was implementing hashCode() but had no equals method.

Change-Id: Ib54862f2507eb4b2d54846e785ca9bd0cc561c16
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-14 09:42:34 +01:00
Dave Borowitz
a4747d57a8 Don't leak AccountConfig references into AccountState
In I9b99490 AccountState was changed to lazily load the project watches
and preferences by passing a lambda referring to the AccountConfig
instance. Unfortunately, AccountConfig holds a reference to an open
Repository instance. In an implementation that does not cache these
instances, they are potentially expensive to hold, whether in terms of
heap or open resources. Plus, they are never closed.

Remove the lazy loading and go back to storing the watches and
preferences directly. This may be suboptimal memory usage, but in
practice will not be as bad as the many MiB of retained heap per entry
we're observing on googlesource.com. We still keep the Supplier
arguments in the AccountState constructor, to keep this change as simple
as possible to fix a production issue; reverting I9b99490 causes many
conflicts.

If we want to lazily load these fields, we will need to come up with an
approach that reopens the repository on demand. Alternatively, if we
decide that lazy loading is not worth the effort, we should remove the
Suppliers from the AccountState interface.

Change-Id: Id020fd89727b0a3377a98cffe8bf2e9cc2731451
2018-02-13 19:08:24 +00:00
Patrick Hiesel
2f08b4113b Check if project state permits write before evaluating Git commands
All of the supported Git commands required the project to be writable.
We have seen HTTP 500s at Google because not all code paths would check
if the project state permits writes.

This commit moves the check in ReceiveCommits to a more central to
mitigate the problem.

Change-Id: Icdea3349583f676580991cd688ae7e9d95564a21
2018-02-13 13:55:21 +01:00
Edwin Kempin
a3d0ed721a Allow to reindex groups and accounts if they are stale
Being able to reindex a group only if it is stale can save effort on
startup of Gerrit slaves (see follow-up change).

Change-Id: I66d5bb09e49a4dfcd9d20db12c4ab818c94fd399
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-13 11:46:22 +01:00
Dave Borowitz
ad49bcd420 Merge "Prefer using Splitter to String.split" 2018-02-12 16:02:31 +00:00
Edwin Kempin
5174d2d95e Prefer using Splitter to String.split
String.split(String) has surprising behaviour [1]:

String[] nothing = "".split(":"); // results in [""]
String[] bunchOfNothing = ":".split(":"); // results in []

More examples:

input  | input.split(":")  | Splitter.on(':').split(input)
=======|===================|==============================
""     | [""]              | [""]
":"    | []                | ["", ""]
":::"  | []                | ["", "", "", ""]
"a:::" | ["a"]             | ["a", "", "", ""]
":::b" | ["", "", "", "b"] | ["", "", "", "b"]

In addition using Splitter makes the code more readable as Splitter has
nicer methods that make it clearer which high-level operation should be
performed. E.g. in some places we can use
Splitter.on(CharMatcher.anyOf(something)) instead of matching on
patterns.

Tests and classes that are used by the GWT UI are not adapted.

[1] http://konigsberg.blogspot.com/2009/11/final-thoughts-java-puzzler-splitting.html

Change-Id: I6f141fb492e2fb94544089d794f245d0885f8649
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-12 11:04:20 +01:00
Edwin Kempin
486c3ce7e3 ChangeField: Log parsing errors of reviewer fields only as warning
If the values are unexpected we don't fail but ignore the values. It's
sufficient to log this as a warning.

Change-Id: I5eb843f469a2bc911c699b748388c0673df54c11
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-12 09:24:09 +01:00
Edwin Kempin
655b00855d ChangeField: Include change ID into error logs when parsing reviewer fields
Without the change ID one doesn't know for which change the reviewer
fields have unexpected values.

Change-Id: I3003acc4cd0f54c13fce4be67d6e092c1dd67412
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-12 09:22:57 +01:00
Edwin Kempin
f1513ada38 Use ExternalId.isValidUsername instead of ExternalId.USER_NAME_PATTERN_REGEX
Since ExternalId.USER_NAME_PATTERN_REGEX is now no longer used by
external callers it is made private.

Change-Id: Id7a108bf39baffc52273879bbf8973dbbea0ae0c
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-09 14:50:07 +01:00
David Pursehouse
2bf19ee6ee Merge branch 'stable-2.15'
* stable-2.15:
  CommitValidators: Debug log when commit validation exception occurs

Change-Id: I66f1a697cdc4da7aad43ebf6ee201d31491c2410
2018-02-09 11:47:29 +09:00
David Pursehouse
b7ff965d13 Merge "Merge branch 'stable-2.15'" 2018-02-09 02:44:47 +00:00
David Pursehouse
f4265008a9 Merge "Test unblock vote on more specific ref" 2018-02-09 01:52:14 +00:00
David Pursehouse
7b00f5ffdc Merge changes I9c3b6976,I2b7eb7f1
* changes:
  Avoid unnecessary creation of GroupControl instance
  Remove unnecessary lookup of group by AccountGroup.Id
2018-02-09 01:51:40 +00:00
David Pursehouse
10b330bc50 Merge branch 'stable-2.15'
* stable-2.15:
  LuceneVersionManager: Fix log error messages
  Increase template test size for polygerrit
  Fixing registration redirect for new OpenID users
  Add config to disable private changes

Change-Id: If9af0e22d3059fc9d71619c429baa570df7f45ff
2018-02-09 10:34:04 +09:00
David Ostrovsky
b51d8cd76d Common GWT module: Exclude testing package for super dev mode
The testing package has its own bazel package (it has BUILD file) and
this is not part of the final artifact built with common:client rule.
However, because of wild card inclusion in Common.gwt.xml, the whole
tree is included in GWT module, when used from Eclipse in super dev mode
debug sessions. To avoid needing to add @GwtIncompatible to all files in
this package, exclude this package from GWT module source path in the GWT
module definition.

Change-Id: Ib36348084d59cc5e10f8dc5c7c627fc4e3323609
2018-02-08 23:40:00 +00:00
Alice Kober-Sotzek
a59d8b7fe3 Avoid unnecessary creation of GroupControl instance
The method GroupControl.Factory#controlFor(AccountGroup.Id) was only
used by GroupsCollection#parseId. When this call is inlined, it becomes
obvious that the creation of a GroupControl instance is unnecessary.

This change has the additional benefit of reducing the use of
AccountGroup.Id in our code base and to keep new code from using
GroupControl.Factory#controlFor(AccountGroup.Id) instead of the
recommended method GroupControl.Factory#controlFor(AccountGroup.UUID).

Change-Id: I9c3b69769a567192ec4582e11bd774c942e1b068
2018-02-08 18:18:06 +01:00
Alice Kober-Sotzek
9f7a20015d Remove unnecessary lookup of group by AccountGroup.Id
Most of Gerrit's core code switched to use AccountGroup.UUID instead of
AccountGroup.Id to refer to a specific group. In theory when we are on
NoteDb for groups, we should only need to support the lookup of a group
by AccountGroup.Id for resource lookups of the REST API.

The lookup by AccountGroup.Id which was present in CreateGroup wasn't
really necessary. It was a relic from former times and probably wasn't
changed up to now as CreateGroupArgs is used as part of the extension
point GroupCreationValidationListener. Considering that we already broke
other extension points relating to groups with this release (as e.g. in
I6d7d97e9), it's better that we make this change now instead of later.

Change-Id: I2b7eb7f1596a1c1147bf552990b793564ba850e6
2018-02-08 17:51:35 +01:00
Han-Wen Nienhuys
e0e6d99b97 Test unblock vote on more specific ref
Change-Id: Iaa130f7df1540843e86003ae0bafe5ec8456c4b6
2018-02-08 17:46:27 +01:00
Hector Oswaldo Caballero
4a2567f29d ChangeField: Fix log error messages
The built-in log formatter uses curly braces instead of '%s'. Without
this change, log messages look like:

  ERROR com.google.gerrit.server.index.change.ChangeField : Invalid
        value for reviewer field: %s

Change-Id: Ia93019c3591528771c88a735067a0ae6ac83cc40
2018-02-08 10:44:35 -05:00
David Pursehouse
6a244f0967 Merge branch 'stable-2.15'
* stable-2.15:
  Bazel: Silent zip output in gerrit-antlr:query_antlr rule
  Provide mvn command output when VERBOSE set
  ReviewerRecommender: Prevent NPE when changeNotes is null
  ReviewerSuggestion: More Javadoc improvements

Change-Id: I433e257961e14b38332997daea8c6e39c42b7d98
2018-02-08 17:30:40 +09:00
David Pursehouse
8f99aa56ed Merge changes If43927fe,I228fd1d5,Ia1e1778a,I4091003f,Ie7ba21dd, ...
* changes:
  RestApiServlet: Merge if with enclosing one
  RestApiServlet: Remove redundant else statements
  RestApiServlet: Use log built-in string formatting
  RestApiServlet: Use defined method to check content type
  RestApiServlet: Extract constant
  RestApiServlet: Extract methods to find kind of request
  RestApiServlet: Collapse identically handled exceptions
2018-02-08 03:58:18 +00:00
David Pursehouse
b81f4073c1 Merge "Merge branch 'stable-2.15' into master" 2018-02-08 02:21:06 +00:00
David Pursehouse
0ba4c4100a Merge "GroupAuditEvent: Fix JavaDoc warnings about invalid member type qualifications" 2018-02-07 23:27:10 +00:00
Dave Borowitz
6aceb38eb7 Merge branch 'stable-2.15' into master
* stable-2.15:
  Document that NoteDb migration requires a large heap
  Move downloaded artifact cache from buck-cache to bazel-cache
  Move downloaded artifact cache from buck-cache to bazel-cache
  Revert "Hide sensitive data from audit and gerrit logs"
  dev-plugins: Improve formatting of reviewer suggestion documentation
  ReviewerSuggestion: Reword Javadoc
  ReviewerRecommender: Add debug log of plugin provided weight
  Handle deleted project in ReindexIfStaleTask
  Disallow tabbing on paper-button
  Handle the ReindexIfStale event when a change is deleted
  PolyGerrit: Fix gr-diff-view arrows to use html code
  Migrate metrics-core to 4.0.2 version
  CreateChange: Fix appending Signed-off-by line after Change-Id
  CreateChange: Only insert Change-Id if there isn't already one
  CreateChangeIT: Disable "Insert Signed-off-by" after test
  Fix gr-group-members to add and delete using group id rather than name
  Fix group member URL

Change-Id: I5ccbc4265266236b55b3c864347e7016cc7a2bd0
2018-02-07 15:04:41 -05:00
Dave Borowitz
e9656a28d1 Merge "Remove outstanding references to buck" 2018-02-07 16:07:16 +00:00
Edwin Kempin
12c32a2388 Merge "CurrentUser: Return Optional from methods that retrieve a property" 2018-02-07 15:36:21 +00:00
Edwin Kempin
04d1c68c93 GroupAuditEvent: Fix JavaDoc warnings about invalid member type qualifications
Change-Id: Id93c8c2c48df2dd7553cc8a9e67cb42992bb5c2e
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-07 16:16:31 +01:00
Dave Borowitz
9c35979e12 Remove outstanding references to buck
Most references are in documentation and comments. The main
developer-visible behavior change is moving the downloaded artifact
cache from ~/.gerritcodereview/buck-cache to bazel-cache, which will
result in re-downloading dependencies on the next build; this had to
happen sooner or later. Alternatives, which are not worth the effort,
include teaching the scripts to accept both locations, or having it
rearrange and/or symlink directories behind the scenes.

There are just a few references remaining, all of which are intentional:

$ git grep -Pi '\bbuck(lets?)?\b' HEAD
HEAD:java/com/google/gerrit/httpd/raw/StaticModule.java:        // https://gerrit-review.googlesource.com/#/c/57570/57/gerrit-httpd/BUCK@32
HEAD:resources/com/google/gerrit/server/mime/mime-types.properties:bucklet = text/x-python
HEAD:resources/com/google/gerrit/server/mime/mime-types.properties:BUCK = text/x-python

Change-Id: Idb93a483451ccf86ba96c379d38008a7894c3f95
2018-02-07 09:16:41 -05:00
Edwin Kempin
b457c1936c Merge "Account: Remove @Column annotations and make members private" 2018-02-07 13:31:57 +00:00
hanwen
3283599404 Merge "In /PROJECT/check.access, warn when there are no branches." 2018-02-07 12:43:07 +00:00
Han-Wen Nienhuys
987dc828f9 Add @Nullable annotations to VersionedMetaData
Change-Id: I8ddb527c0036faf0fb98456d0f0629ff97fc30c6
2018-02-07 11:48:40 +01:00
Han-Wen Nienhuys
8eb5f2bde0 In /PROJECT/check.access, warn when there are no branches.
This will further help troubleshoot access issues.

Change-Id: I3fa6f616ec65a79f1819dc4c59de9a65a05d8f02
2018-02-07 11:43:38 +01:00
Hector Oswaldo Caballero
6c4c287334 RestApiServlet: Merge if with enclosing one
Change-Id: If43927fee5e069db8fb3f3eaa79c3e2c0b28f9c1
2018-02-07 05:21:48 -05:00
Hector Oswaldo Caballero
1767c1ecd6 RestApiServlet: Remove redundant else statements
Change-Id: I228fd1d59e46a9861a33f4f784ca6064b40ca129
2018-02-07 05:21:48 -05:00
Hector Oswaldo Caballero
0ebd41f430 RestApiServlet: Use log built-in string formatting
As reported by Sonar, logging arguments should not require evaluation.

Change-Id: Ia1e1778a1d68451733bdf63705e215e84b8ceb02
2018-02-07 05:21:48 -05:00
Hector Oswaldo Caballero
534847b982 RestApiServlet: Use defined method to check content type
Change-Id: I4091003ff38af59775e887e6d7c22aa96a4b5cc7
2018-02-07 05:21:48 -05:00
Hector Oswaldo Caballero
a774a4f14d RestApiServlet: Extract constant
Change-Id: Ie7ba21dd364a48ca0616a672e45e8c9bb5fcb384
2018-02-07 05:21:48 -05:00