Skip to content

Commit

Permalink
Update the underlying stream position after deserialization (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikegoatly authored Jul 25, 2022
1 parent 2afefca commit 9fb00c3
Show file tree
Hide file tree
Showing 9 changed files with 715 additions and 597 deletions.
236 changes: 118 additions & 118 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,118 +1,118 @@
trigger:
branches:
include:
- master
paths:
include:
- src
- test

variables:
majorVersion: 3
minorVersion: 0
patchVersion: 1
project: src/Lifti.Core/Lifti.Core.csproj
testProject: test/Lifti.Tests/Lifti.Tests.csproj
buildConfiguration: 'Release'

stages:
- stage: Build
displayName: Build nuget packages

jobs:
- job: Build

pool:
vmImage: 'windows-latest'

steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '6.0.x'
- task: DotNetCoreCLI@2
displayName: "NuGet Restore"
inputs:
command: restore
projects: '**/*.csproj'
verbosityRestore: 'Normal'
- task: DotNetCoreCLI@2
displayName: Run unit tests
inputs:
command: 'test'
projects: $(testProject)
- task: DotNetCoreCLI@2
displayName: Pack CI nuget version
inputs:
command: 'pack'
packagesToPack: $(project)
packDirectory: '$(Build.ArtifactStagingDirectory)/packages/ci'
versioningScheme: 'byPrereleaseNumber'
majorVersion: '$(majorVersion)'
minorVersion: '$(minorVersion)'
patchVersion: '$(patchVersion)'
verbosityPack: 'Normal'
arguments: '--configuration $(buildConfiguration)'

- task: PublishSymbols@2
inputs:
SearchPattern: '**/bin/**/*.pdb'
SymbolServerType: 'TeamServices'

- task: DotNetCoreCLI@2
displayName: Pack release nuget version
inputs:
command: 'pack'
packagesToPack: $(project)
packDirectory: '$(Build.ArtifactStagingDirectory)/packages/release'
versioningScheme: 'off'
buildProperties: 'PackageVersion=$(majorVersion).$(minorVersion).$(patchVersion)'
verbosityPack: 'Normal'
arguments: '--configuration $(buildConfiguration)'

- publish: '$(Build.ArtifactStagingDirectory)/packages'
artifact: 'packages'

- stage: PublishCINugetPackage
displayName: Publish to CI feed
dependsOn: Build
condition: succeeded()

jobs:
- job: PublishCI
pool:
vmImage: 'ubuntu-latest'

steps:
- checkout: none

- download: current
artifact: 'packages'

- task: DotNetCoreCLI@2
inputs:
command: 'push'
packagesToPush: '$(Pipeline.Workspace)/packages/ci/*.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: '21c23043-21b0-4e5a-8557-00b88fc52fd4/9f4e269d-a35a-4657-b2a3-b56b01c01f8c'

- stage: 'PublishReleaseNuGetPackage'
displayName: 'Publish Release NuGet Package'
dependsOn: 'PublishCINugetPackage'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
jobs:
- deployment:
pool:
vmImage: 'ubuntu-latest'
environment: 'Nuget'
strategy:
runOnce:
deploy:
steps:
- task: NuGetCommand@2
displayName: 'Push NuGet Package'
inputs:
command: 'push'
packagesToPush: '$(Pipeline.Workspace)/packages/release/*.nupkg'
nuGetFeedType: 'external'
publishFeedCredentials: 'NuGet'
trigger:
branches:
include:
- master
paths:
include:
- src
- test

variables:
majorVersion: 3
minorVersion: 1
patchVersion: 0
project: src/Lifti.Core/Lifti.Core.csproj
testProject: test/Lifti.Tests/Lifti.Tests.csproj
buildConfiguration: 'Release'

stages:
- stage: Build
displayName: Build nuget packages

jobs:
- job: Build

pool:
vmImage: 'windows-latest'

steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '6.0.x'
- task: DotNetCoreCLI@2
displayName: "NuGet Restore"
inputs:
command: restore
projects: '**/*.csproj'
verbosityRestore: 'Normal'
- task: DotNetCoreCLI@2
displayName: Run unit tests
inputs:
command: 'test'
projects: $(testProject)
- task: DotNetCoreCLI@2
displayName: Pack CI nuget version
inputs:
command: 'pack'
packagesToPack: $(project)
packDirectory: '$(Build.ArtifactStagingDirectory)/packages/ci'
versioningScheme: 'byPrereleaseNumber'
majorVersion: '$(majorVersion)'
minorVersion: '$(minorVersion)'
patchVersion: '$(patchVersion)'
verbosityPack: 'Normal'
arguments: '--configuration $(buildConfiguration)'

- task: PublishSymbols@2
inputs:
SearchPattern: '**/bin/**/*.pdb'
SymbolServerType: 'TeamServices'

- task: DotNetCoreCLI@2
displayName: Pack release nuget version
inputs:
command: 'pack'
packagesToPack: $(project)
packDirectory: '$(Build.ArtifactStagingDirectory)/packages/release'
versioningScheme: 'off'
buildProperties: 'PackageVersion=$(majorVersion).$(minorVersion).$(patchVersion)'
verbosityPack: 'Normal'
arguments: '--configuration $(buildConfiguration)'

- publish: '$(Build.ArtifactStagingDirectory)/packages'
artifact: 'packages'

- stage: PublishCINugetPackage
displayName: Publish to CI feed
dependsOn: Build
condition: succeeded()

jobs:
- job: PublishCI
pool:
vmImage: 'ubuntu-latest'

steps:
- checkout: none

- download: current
artifact: 'packages'

- task: DotNetCoreCLI@2
inputs:
command: 'push'
packagesToPush: '$(Pipeline.Workspace)/packages/ci/*.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: '21c23043-21b0-4e5a-8557-00b88fc52fd4/9f4e269d-a35a-4657-b2a3-b56b01c01f8c'

- stage: 'PublishReleaseNuGetPackage'
displayName: 'Publish Release NuGet Package'
dependsOn: 'PublishCINugetPackage'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
jobs:
- deployment:
pool:
vmImage: 'ubuntu-latest'
environment: 'Nuget'
strategy:
runOnce:
deploy:
steps:
- task: NuGetCommand@2
displayName: 'Push NuGet Package'
inputs:
command: 'push'
packagesToPush: '$(Pipeline.Workspace)/packages/release/*.nupkg'
nuGetFeedType: 'external'
publishFeedCredentials: 'NuGet'
22 changes: 15 additions & 7 deletions src/Lifti.Core/Serialization/Binary/V2IndexReader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Threading.Tasks;
Expand All @@ -11,7 +12,8 @@ internal class V2IndexReader<TKey> : IIndexReader<TKey>
private readonly Stream underlyingStream;
private readonly bool disposeStream;
private readonly IKeySerializer<TKey> keySerializer;
private readonly MemoryStream buffer;
private readonly MemoryStream buffer;
private long initialUnderlyingStreamOffset = 0L;
protected readonly BinaryReader reader;

public V2IndexReader(Stream stream, bool disposeStream, IKeySerializer<TKey> keySerializer)
Expand All @@ -20,7 +22,7 @@ public V2IndexReader(Stream stream, bool disposeStream, IKeySerializer<TKey> key
this.disposeStream = disposeStream;
this.keySerializer = keySerializer;

this.buffer = new MemoryStream((int)this.underlyingStream.Length);
this.buffer = new MemoryStream((int)(this.underlyingStream.Length - this.underlyingStream.Position));
this.reader = new BinaryReader(this.buffer);
}

Expand Down Expand Up @@ -61,14 +63,19 @@ public async Task ReadIntoAsync(FullTextIndex<TKey> index)
new DocumentStatistics(fieldTokenCounts.ToImmutable(), totalTokenCount));
}

index.SetRootWithLock(this.DeserializeNode(index.IndexNodeFactory, 0));
index.SetRootWithLock(this.DeserializeNode(index.IndexNodeFactory, 0));

if (this.reader.ReadInt32() != -1)
{
throw new DeserializationException(ExceptionMessages.MissingIndexTerminator);
}

if (this.underlyingStream.CanSeek)
{
this.underlyingStream.Position = this.buffer.Position + initialUnderlyingStreamOffset;
}
}

}

private IndexNode DeserializeNode(IIndexNodeFactory nodeFactory, int depth)
{
var textLength = this.reader.ReadInt32();
Expand Down Expand Up @@ -198,7 +205,8 @@ private int DeserializeAbbreviatedData(LocationEntrySerializationOptimizations s
}

private async Task FillBufferAsync()
{
{
this.initialUnderlyingStreamOffset = this.underlyingStream.Position;
await this.underlyingStream.CopyToAsync(this.buffer).ConfigureAwait(false);
this.buffer.Position = 0;
}
Expand Down
Loading

0 comments on commit 9fb00c3

Please sign in to comment.