-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#4129] improvement(core): Support hold multiple tree lock within a t…
…hread at the same time (#4130) ### What changes were proposed in this pull request? Add the value of the name identifier in the holdingThreadTimestamp to support holding multiple tree lock at the same time. ### Why are the changes needed? To support more user sceanrio Fix: #4129 ### Does this PR introduce _any_ user-facing change? N/A. ### How was this patch tested? Add new test class `TestTreeLockUtils`
- Loading branch information
Showing
4 changed files
with
131 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
core/src/test/java/com/datastrato/gravitino/lock/TestTreeLockUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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.datastrato.gravitino.lock; | ||
|
||
import static com.datastrato.gravitino.Configs.TREE_LOCK_CLEAN_INTERVAL; | ||
import static com.datastrato.gravitino.Configs.TREE_LOCK_MAX_NODE_IN_MEMORY; | ||
import static com.datastrato.gravitino.Configs.TREE_LOCK_MIN_NODE_IN_MEMORY; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import com.datastrato.gravitino.Config; | ||
import com.datastrato.gravitino.GravitinoEnv; | ||
import com.datastrato.gravitino.NameIdentifier; | ||
import org.apache.commons.lang3.reflect.FieldUtils; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestTreeLockUtils { | ||
|
||
@Test | ||
void testHolderMultipleLock() throws Exception { | ||
Config config = mock(Config.class); | ||
doReturn(100000L).when(config).get(TREE_LOCK_MAX_NODE_IN_MEMORY); | ||
doReturn(1000L).when(config).get(TREE_LOCK_MIN_NODE_IN_MEMORY); | ||
doReturn(36000L).when(config).get(TREE_LOCK_CLEAN_INTERVAL); | ||
FieldUtils.writeField(GravitinoEnv.getInstance(), "lockManager", new LockManager(config), true); | ||
|
||
TreeLockUtils.doWithTreeLock( | ||
NameIdentifier.of("test"), | ||
LockType.READ, | ||
() -> | ||
TreeLockUtils.doWithTreeLock( | ||
NameIdentifier.of("test", "test1"), LockType.WRITE, () -> null)); | ||
} | ||
} |