Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
根据map的Key/ValueType提前序列化redo log的key、value
- Loading branch information
1 parent
ae56597
commit 1ebf6a5
Showing
6 changed files
with
151 additions
and
22 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
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
32 changes: 32 additions & 0 deletions
32
lealone-transaction/src/main/java/org/lealone/transaction/log/RedoLogValue.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
/* | |||
* 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 org.lealone.transaction.log; | |||
|
|||
import java.nio.ByteBuffer; | |||
|
|||
public class RedoLogValue { | |||
int mapId; | |||
ByteBuffer key; | |||
ByteBuffer value; | |||
|
|||
public RedoLogValue(int mapId, ByteBuffer key, ByteBuffer value) { | |||
this.mapId = mapId; | |||
this.key = key; | |||
this.value = value; | |||
} | |||
} |
77 changes: 77 additions & 0 deletions
77
lealone-transaction/src/main/java/org/lealone/transaction/log/RedoLogValueType.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,77 @@ | |||
/* | |||
* 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 org.lealone.transaction.log; | |||
|
|||
import java.nio.ByteBuffer; | |||
|
|||
import org.lealone.common.message.DbException; | |||
import org.lealone.common.util.DataUtils; | |||
import org.lealone.storage.type.DataType; | |||
import org.lealone.storage.type.WriteBuffer; | |||
|
|||
public class RedoLogValueType implements DataType { | |||
|
|||
@Override | |||
public int compare(Object a, Object b) { | |||
throw DbException.getUnsupportedException("compare"); | |||
} | |||
|
|||
@Override | |||
public int getMemory(Object obj) { | |||
throw DbException.getUnsupportedException("getMemory"); | |||
} | |||
|
|||
@Override | |||
public void write(WriteBuffer buff, Object obj) { | |||
RedoLogValue v = (RedoLogValue) obj; | |||
buff.putVarInt(v.mapId); | |||
buff.putVarInt(v.key.remaining()); | |||
buff.put(v.key); | |||
buff.putVarInt(v.value.remaining()); | |||
buff.put(v.value); | |||
} | |||
|
|||
@Override | |||
public void write(WriteBuffer buff, Object[] obj, int len, boolean key) { | |||
for (int i = 0; i < len; i++) { | |||
write(buff, obj[i]); | |||
} | |||
} | |||
|
|||
@Override | |||
public Object read(ByteBuffer buff) { | |||
int mapId = DataUtils.readVarInt(buff); | |||
|
|||
byte[] key = new byte[DataUtils.readVarInt(buff)]; | |||
buff.get(key); | |||
ByteBuffer keyBuffer = ByteBuffer.wrap(key); | |||
|
|||
byte[] value = new byte[DataUtils.readVarInt(buff)]; | |||
buff.get(value); | |||
ByteBuffer valueBuffer = ByteBuffer.wrap(value); | |||
return new RedoLogValue(mapId, keyBuffer, valueBuffer); | |||
} | |||
|
|||
@Override | |||
public void read(ByteBuffer buff, Object[] obj, int len, boolean key) { | |||
for (int i = 0; i < len; i++) { | |||
obj[i] = read(buff); | |||
} | |||
} | |||
|
|||
} |