Implement PureRevertCache
Computing if a change is a pure revert of another change or commit is an expensive operation as it requires a Git merge. This is especially true for large Git repositories. However, this information is easy to cache in a persistent cache as it can be keyed by the SHA1s of the commits that we want to diff. Given that this computation runs many times if the Prolog fact is used because we freshly compute the submit rules often, this commit builds a persisted cache for it. There are many existing tests that cover the behavior in ChangeIT. This commit adds a serializer for Protobuf to ensure we are not using the default Java serialization as well as a test. Change-Id: Id79e2fb2f6646d8e48fdfc3a3b0bcf03f51b1400
This commit is contained in:
		
							
								
								
									
										38
									
								
								java/com/google/gerrit/server/cache/serialize/ProtobufSerializer.java
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								java/com/google/gerrit/server/cache/serialize/ProtobufSerializer.java
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| // Copyright (C) 2019 The Android Open Source Project | ||||
| // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | ||||
| // | ||||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | ||||
| // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| package com.google.gerrit.server.cache.serialize; | ||||
|  | ||||
| import com.google.gerrit.proto.Protos; | ||||
| import com.google.protobuf.MessageLite; | ||||
| import com.google.protobuf.Parser; | ||||
|  | ||||
| /** A CacheSerializer for Protobuf messages. */ | ||||
| public class ProtobufSerializer<T extends MessageLite> implements CacheSerializer<T> { | ||||
|   private final Parser<T> parser; | ||||
|  | ||||
|   public ProtobufSerializer(Parser<T> parser) { | ||||
|     this.parser = parser; | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public byte[] serialize(T object) { | ||||
|     return Protos.toByteArray(object); | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public T deserialize(byte[] in) { | ||||
|     return Protos.parseUnchecked(parser, in); | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Patrick Hiesel
					Patrick Hiesel