Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Snappy support for windows #11

Open
mikhail-khalizev opened this issue Sep 29, 2021 · 1 comment
Open

Add Snappy support for windows #11

mikhail-khalizev opened this issue Sep 29, 2021 · 1 comment

Comments

@mikhail-khalizev
Copy link

Native library leveldb compiled without Snappy.
As result when you open existence leveldb database, which is used Snappy, corrupted compressed block contents error occurs.
So my suggestion to add Snappy support!

format.cc:

    case kSnappyCompression: {
      size_t ulength = 0;
      if (!port::Snappy_GetUncompressedLength(data, n, &ulength)) {          
        delete[] buf;
        return Status::Corruption("corrupted compressed block contents");   // <--- Always error
      }

port_win.h:

inline bool Snappy_GetUncompressedLength(const char* input, size_t length,
                                         size_t* result) {
#ifdef SNAPPY
  return snappy::GetUncompressedLength(input, length, result);
#else
  return false;     // <-- always false
#endif
}
@mikhail-khalizev
Copy link
Author

mikhail-khalizev commented Sep 29, 2021

This is leveldb.dll v1.23: leveldb-with-snappy-win-x64-release.zip

Workaround for current LevelDB.Net version:

            NativeLibrary.SetDllImportResolver(typeof(LevelDBInterop).Assembly, Resolver);
        private IntPtr Resolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
        {
            if (!string.Equals(libraryName, "leveldb.dll", StringComparison.OrdinalIgnoreCase)) 
                return default;
            
            var directory = Path.GetDirectoryName(GetType().Assembly.Location);
            if (string.IsNullOrEmpty(directory))
                return default;

            var filePath = Path.Combine(directory, libraryName);
            NativeLibrary.TryLoad(filePath, out var handle);
            return handle;
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant